Influence last_stream_id to nghttp2_session_want_{read,write}

This commit is contained in:
Tatsuhiro Tsujikawa 2014-11-29 23:12:55 +09:00
parent 7ff0797535
commit 152a20a416
1 changed files with 28 additions and 10 deletions

View File

@ -5589,15 +5589,24 @@ int nghttp2_session_want_read(nghttp2_session *session) {
num_active_streams = session_get_num_active_streams(session); num_active_streams = session_get_num_active_streams(session);
/* Unless GOAWAY is sent or received, we always want to read /* Unless termination GOAWAY is sent or received, we always want to
incoming frames. After GOAWAY is sent or received, we are only read incoming frames. */
interested in active streams. */
if (num_active_streams > 0) { if (num_active_streams > 0) {
return 1; return 1;
} }
return 1; /* If there is no active streams, we check last_stream_id peer sent
to us. Here is the asymmetry between server and client. For
server, if client cannot make new request, current conneciton is
no use. Server push might be going, but it is idempotent and can
be safely retried with the new connection. For client side, the
theory is the same. */
if (session->server) {
return session->local_last_stream_id > session->last_recv_stream_id;
} else {
return (uint32_t)session->remote_last_stream_id >= session->next_stream_id;
}
} }
int nghttp2_session_want_write(nghttp2_session *session) { int nghttp2_session_want_write(nghttp2_session *session) {
@ -5613,11 +5622,10 @@ int nghttp2_session_want_write(nghttp2_session *session) {
num_active_streams = session_get_num_active_streams(session); num_active_streams = session_get_num_active_streams(session);
/* /*
* Unless GOAWAY is sent or received, we want to write frames if * Unless termination GOAWAY is sent or received, we want to write
* there is pending ones. If pending frame is request/push response * frames if there is pending ones. If pending frame is request/push
* HEADERS and concurrent stream limit is reached, we don't want to * response HEADERS and concurrent stream limit is reached, we don't
* write them. After GOAWAY is sent or received, we want to write * want to write them.
* frames if there is pending ones AND there are active frames.
*/ */
if (session->aob.item == NULL && nghttp2_pq_empty(&session->ob_pq) && if (session->aob.item == NULL && nghttp2_pq_empty(&session->ob_pq) &&
@ -5632,7 +5640,17 @@ int nghttp2_session_want_write(nghttp2_session *session) {
return 1; return 1;
} }
return 1; /* If there is no active streams, we check last_stream_id peer sent
to us. Here is the asymmetry between server and client. For
server, if client cannot make new request, current conneciton is
no use. Server push might be going, but it is idempotent and can
be safely retried with the new connection. For client side, the
theory is the same. */
if (session->server) {
return session->local_last_stream_id > session->last_recv_stream_id;
} else {
return (uint32_t)session->remote_last_stream_id >= session->next_stream_id;
}
} }
int nghttp2_session_add_ping(nghttp2_session *session, uint8_t flags, int nghttp2_session_add_ping(nghttp2_session *session, uint8_t flags,