From d0d0009a50eafb905ca53137d14b7cc290722f8c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 28 Nov 2013 23:26:34 +0900 Subject: [PATCH] Use largest valid stream ID which passed to callback as last-stream-ID Previously we use largest stream ID received so far as last-stream-ID, and it is irrevant that it is passed to the callback (thus upper layer). Now the stream ID which is passed to callback is eligible to last-stream-ID. --- lib/nghttp2_session.c | 9 +++++---- lib/nghttp2_session.h | 7 ++++++- lib/nghttp2_submit.c | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 55c32e3f..eed667de 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -190,8 +190,8 @@ static int nghttp2_session_new(nghttp2_session **session_ptr, } memset(*session_ptr, 0, sizeof(nghttp2_session)); - /* next_stream_id and last_recv_stream_id are initialized in either - nghttp2_session_client_new or nghttp2_session_server_new */ + /* next_stream_id is initialized in either + nghttp2_session_client_new2 or nghttp2_session_server_new2 */ (*session_ptr)->next_seq = 0; @@ -325,7 +325,6 @@ int nghttp2_session_client_new2(nghttp2_session **session_ptr, if(r == 0) { /* IDs for use in client */ (*session_ptr)->next_stream_id = 1; - (*session_ptr)->last_recv_stream_id = 0; } return r; } @@ -351,7 +350,6 @@ int nghttp2_session_server_new2(nghttp2_session **session_ptr, if(r == 0) { /* IDs for use in client */ (*session_ptr)->next_stream_id = 2; - (*session_ptr)->last_recv_stream_id = 0; } return r; } @@ -1919,6 +1917,7 @@ int nghttp2_session_on_request_headers_received(nghttp2_session *session, if(!stream) { return NGHTTP2_ERR_NOMEM; } + session->last_proc_stream_id = session->last_recv_stream_id; rv = nghttp2_session_call_on_frame_received(session, frame); if(rv != 0) { return rv; @@ -2588,6 +2587,7 @@ int nghttp2_session_on_push_promise_received(nghttp2_session *session, if(!promised_stream) { return NGHTTP2_ERR_NOMEM; } + session->last_proc_stream_id = session->last_recv_stream_id; return nghttp2_session_call_on_frame_received(session, frame); } @@ -3723,6 +3723,7 @@ int nghttp2_session_upgrade(nghttp2_session *session, if(session->server) { nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); session->last_recv_stream_id = 1; + session->last_proc_stream_id = 1; } else { nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR); session->next_stream_id += 2; diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index afa8a4a7..489ec94a 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -118,7 +118,12 @@ struct nghttp2_session { uint8_t server; /* Next Stream ID. Made unsigned int to detect >= (1 << 31). */ uint32_t next_stream_id; + /* The largest stream ID received so far */ int32_t last_recv_stream_id; + /* The largest stream ID which has been processed in some way. This + value will be used as last-stream-id when sending GOAWAY + frame. */ + int32_t last_proc_stream_id; /* Counter of unique ID of PING. Wraps when it exceeds NGHTTP2_MAX_UNIQUE_ID */ uint32_t next_unique_id; @@ -156,7 +161,7 @@ struct nghttp2_session { /* Flags indicating GOAWAY is sent and/or recieved. The flags are composed by bitwise OR-ing nghttp2_goaway_flag. */ uint8_t goaway_flags; - /* This is the value in GOAWAY frame sent by remote endpoint. */ + /* This is the value in GOAWAY frame received from remote endpoint. */ int32_t last_stream_id; /* Non-zero indicates connection-level flow control on remote side diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index ac41970f..266b52ca 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -202,7 +202,7 @@ int nghttp2_submit_goaway(nghttp2_session *session, uint8_t flags, nghttp2_error_code error_code, uint8_t *opaque_data, size_t opaque_data_len) { - return nghttp2_session_add_goaway(session, session->last_recv_stream_id, + return nghttp2_session_add_goaway(session, session->last_stream_id, error_code, opaque_data, opaque_data_len); }