From ad64f11a95c2449e3e7284bbb4852d74797d6b00 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 30 Oct 2013 23:43:40 +0900 Subject: [PATCH] Remove code submitting WINDOW_UPDATE with negative delta It is effectively dead code because we should have already submit WINDOW_UPDATE before this case happens. --- lib/nghttp2_helper.c | 4 +++- lib/nghttp2_session.h | 3 ++- lib/nghttp2_stream.h | 3 ++- lib/nghttp2_submit.c | 16 ---------------- tests/nghttp2_helper_test.c | 2 +- tests/nghttp2_session_test.c | 20 ++++++++------------ 6 files changed, 16 insertions(+), 32 deletions(-) diff --git a/lib/nghttp2_helper.c b/lib/nghttp2_helper.c index 368f3de3..9167ccbb 100644 --- a/lib/nghttp2_helper.c +++ b/lib/nghttp2_helper.c @@ -118,7 +118,8 @@ int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr, *recv_window_size_ptr += recv_reduction_diff; } else { /* If *recv_window_size_ptr > 0, then those bytes are - considered to be backed to the remote peer, so it is + considered to be backed to the remote peer (by + WINDOW_UPDATE with the adjusted *delta_ptr), so it is effectively 0 now. */ *recv_window_size_ptr = recv_reduction_diff; } @@ -142,6 +143,7 @@ int nghttp2_adjust_local_window_size(int32_t *local_window_size_ptr, *local_window_size_ptr += *delta_ptr; *recv_window_size_ptr += *delta_ptr; *recv_reduction_ptr -= *delta_ptr; + *delta_ptr = 0; } return 0; } diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index 381224bc..afa8a4a7 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -171,7 +171,8 @@ struct nghttp2_session { current initial window size of remote endpoint. */ int32_t remote_window_size; /* Keep track of the number of bytes received without - WINDOW_UPDATE. */ + WINDOW_UPDATE. This could be negative after submitting negative + value to WINDOW_UPDATE. */ int32_t recv_window_size; /* The amount of recv_window_size cut using submitting negative value to WINDOW_UPDATE */ diff --git a/lib/nghttp2_stream.h b/lib/nghttp2_stream.h index 73cce35d..0f9e72a2 100644 --- a/lib/nghttp2_stream.h +++ b/lib/nghttp2_stream.h @@ -113,7 +113,8 @@ typedef struct { current initial window size of remote endpoint. */ int32_t remote_window_size; /* Keep track of the number of bytes received without - WINDOW_UPDATE. */ + WINDOW_UPDATE. This could be negative after submitting negative + value to WINDOW_UPDATE */ int32_t recv_window_size; /* The amount of recv_window_size cut using submitting negative value to WINDOW_UPDATE */ diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index 201b6f44..2a4dff7a 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -269,14 +269,6 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags, if(rv != 0) { return rv; } - if(!(session->opt_flags & - NGHTTP2_OPTMASK_NO_AUTO_CONNECTION_WINDOW_UPDATE) && - window_size_increment < 0 && - nghttp2_should_send_window_update(session->local_window_size, - session->recv_window_size)) { - window_size_increment = session->recv_window_size; - session->recv_window_size = 0; - } } else { stream = nghttp2_session_get_stream(session, stream_id); if(stream) { @@ -290,14 +282,6 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags, if(rv != 0) { return rv; } - if(!(session->opt_flags & - NGHTTP2_OPTMASK_NO_AUTO_STREAM_WINDOW_UPDATE) && - window_size_increment < 0 && - nghttp2_should_send_window_update(stream->local_window_size, - stream->recv_window_size)) { - window_size_increment = stream->recv_window_size; - stream->recv_window_size = 0; - } } else { return NGHTTP2_ERR_STREAM_CLOSED; } diff --git a/tests/nghttp2_helper_test.c b/tests/nghttp2_helper_test.c index 80159fc1..93699c05 100644 --- a/tests/nghttp2_helper_test.c +++ b/tests/nghttp2_helper_test.c @@ -83,7 +83,7 @@ void test_nghttp2_adjust_local_window_size(void) CU_ASSERT(100 == local_window_size); CU_ASSERT(-1 == recv_window_size); CU_ASSERT(1 == recv_reduction); - CU_ASSERT(-1 == delta); + CU_ASSERT(0 == delta); delta = 1; CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index f9738bcf..f1ce973b 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -2508,23 +2508,21 @@ void test_nghttp2_submit_window_update_local_window_size(void) CU_ASSERT(0 == nghttp2_session_send(session)); /* Let's decrement local window size */ - stream->recv_window_size = 65536; + stream->recv_window_size = 4096; CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, -stream->local_window_size / 2)); CU_ASSERT(32768 == stream->local_window_size); - CU_ASSERT(0 == stream->recv_window_size); + CU_ASSERT(-28672 == stream->recv_window_size); CU_ASSERT(32768 == stream->recv_reduction); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); - CU_ASSERT(32768 == OB_CTRL(item)->window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(item == NULL); /* Increase local window size */ CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 16384)); CU_ASSERT(49152 == stream->local_window_size); - CU_ASSERT(16384 == stream->recv_window_size); + CU_ASSERT(-12288 == stream->recv_window_size); CU_ASSERT(16384 == stream->recv_reduction); CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); @@ -2548,22 +2546,20 @@ void test_nghttp2_submit_window_update_local_window_size(void) CU_ASSERT(0 == nghttp2_session_send(session)); /* Go decrement part */ - session->recv_window_size = 65536; + session->recv_window_size = 4096; CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, -session->local_window_size/2)); CU_ASSERT(32768 == session->local_window_size); - CU_ASSERT(0 == session->recv_window_size); + CU_ASSERT(-28672 == session->recv_window_size); CU_ASSERT(32768 == session->recv_reduction); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == OB_CTRL_TYPE(item)); - CU_ASSERT(32768 == OB_CTRL(item)->window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(item == NULL); /* Increase local window size */ CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 16384)); CU_ASSERT(49152 == session->local_window_size); - CU_ASSERT(16384 == session->recv_window_size); + CU_ASSERT(-12288 == session->recv_window_size); CU_ASSERT(16384 == session->recv_reduction); CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session));