Commit 905e16cb authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Simplify session_after_frame_sent1

parent 9d4e8eeb
...@@ -2483,14 +2483,74 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2483,14 +2483,74 @@ static int session_after_frame_sent1(nghttp2_session *session) {
nghttp2_outbound_item *item = aob->item; nghttp2_outbound_item *item = aob->item;
nghttp2_bufs *framebufs = &aob->framebufs; nghttp2_bufs *framebufs = &aob->framebufs;
nghttp2_frame *frame; nghttp2_frame *frame;
nghttp2_stream *stream;
frame = &item->frame; frame = &item->frame;
if (frame->hd.type != NGHTTP2_DATA) { if (frame->hd.type == NGHTTP2_DATA) {
nghttp2_data_aux_data *aux_data;
aux_data = &item->aux_data.data;
stream = nghttp2_session_get_stream(session, frame->hd.stream_id);
/* We update flow control window after a frame was completely
sent. This is possible because we choose payload length not to
exceed the window */
session->remote_window_size -= (int32_t)frame->hd.length;
if (stream) {
stream->remote_window_size -= (int32_t)frame->hd.length;
}
if (stream && aux_data->eof) {
rv = nghttp2_stream_detach_item(stream);
if (nghttp2_is_fatal(rv)) {
return rv;
}
/* Call on_frame_send_callback after
nghttp2_stream_detach_item(), so that application can issue
nghttp2_submit_data() in the callback. */
if (session->callbacks.on_frame_send_callback) {
rv = session_call_on_frame_send(session, frame);
if (nghttp2_is_fatal(rv)) {
return rv;
}
}
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
int stream_closed;
stream_closed =
(stream->shut_flags & NGHTTP2_SHUT_RDWR) == NGHTTP2_SHUT_RDWR;
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR);
rv = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
if (nghttp2_is_fatal(rv)) {
return rv;
}
/* stream may be NULL if it was closed */
if (stream_closed) {
stream = NULL;
}
}
return 0;
}
if (session->callbacks.on_frame_send_callback) {
rv = session_call_on_frame_send(session, frame);
if (nghttp2_is_fatal(rv)) {
return rv;
}
}
return 0;
}
/* non-DATA frame */
if (frame->hd.type == NGHTTP2_HEADERS || if (frame->hd.type == NGHTTP2_HEADERS ||
frame->hd.type == NGHTTP2_PUSH_PROMISE) { frame->hd.type == NGHTTP2_PUSH_PROMISE) {
if (nghttp2_bufs_next_present(framebufs)) { if (nghttp2_bufs_next_present(framebufs)) {
DEBUGF(fprintf(stderr, "send: CONTINUATION exists, just return\n")); DEBUGF(fprintf(stderr, "send: CONTINUATION exists, just return\n"));
return 0; return 0;
...@@ -2503,11 +2563,10 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2503,11 +2563,10 @@ static int session_after_frame_sent1(nghttp2_session *session) {
switch (frame->hd.type) { switch (frame->hd.type) {
case NGHTTP2_HEADERS: { case NGHTTP2_HEADERS: {
nghttp2_headers_aux_data *aux_data; nghttp2_headers_aux_data *aux_data;
nghttp2_stream *stream;
stream = nghttp2_session_get_stream(session, frame->hd.stream_id); stream = nghttp2_session_get_stream(session, frame->hd.stream_id);
if (!stream) { if (!stream) {
break; return 0;
} }
switch (frame->headers.cat) { switch (frame->headers.cat) {
...@@ -2532,7 +2591,7 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2532,7 +2591,7 @@ static int session_after_frame_sent1(nghttp2_session *session) {
/* TODO nghttp2_submit_data() may fail if stream has already /* TODO nghttp2_submit_data() may fail if stream has already
DATA frame item. We might have to handle it here. */ DATA frame item. We might have to handle it here. */
} }
break; return 0;
} }
case NGHTTP2_HCAT_PUSH_RESPONSE: case NGHTTP2_HCAT_PUSH_RESPONSE:
stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_PUSH); stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_PUSH);
...@@ -2560,22 +2619,24 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2560,22 +2619,24 @@ static int session_after_frame_sent1(nghttp2_session *session) {
/* TODO nghttp2_submit_data() may fail if stream has already /* TODO nghttp2_submit_data() may fail if stream has already
DATA frame item. We might have to handle it here. */ DATA frame item. We might have to handle it here. */
} }
break; return 0;
default:
/* Unreachable */
assert(0);
return 0;
} }
break;
} }
case NGHTTP2_PRIORITY: { case NGHTTP2_PRIORITY:
nghttp2_stream *stream;
if (session->server) { if (session->server) {
break; return 0;
;
} }
stream = nghttp2_session_get_stream_raw(session, frame->hd.stream_id); stream = nghttp2_session_get_stream_raw(session, frame->hd.stream_id);
if (!stream) { if (!stream) {
if (!session_detect_idle_stream(session, frame->hd.stream_id)) { if (!session_detect_idle_stream(session, frame->hd.stream_id)) {
break; return 0;
} }
stream = nghttp2_session_open_stream( stream = nghttp2_session_open_stream(
...@@ -2598,15 +2659,14 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2598,15 +2659,14 @@ static int session_after_frame_sent1(nghttp2_session *session) {
return rv; return rv;
} }
break; return 0;
}
case NGHTTP2_RST_STREAM: case NGHTTP2_RST_STREAM:
rv = nghttp2_session_close_stream(session, frame->hd.stream_id, rv = nghttp2_session_close_stream(session, frame->hd.stream_id,
frame->rst_stream.error_code); frame->rst_stream.error_code);
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
return rv; return rv;
} }
break; return 0;
case NGHTTP2_GOAWAY: { case NGHTTP2_GOAWAY: {
nghttp2_goaway_aux_data *aux_data; nghttp2_goaway_aux_data *aux_data;
...@@ -2620,15 +2680,15 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2620,15 +2680,15 @@ static int session_after_frame_sent1(nghttp2_session *session) {
session->goaway_flags |= NGHTTP2_GOAWAY_SENT; session->goaway_flags |= NGHTTP2_GOAWAY_SENT;
rv = session_close_stream_on_goaway(session, rv = session_close_stream_on_goaway(session, frame->goaway.last_stream_id,
frame->goaway.last_stream_id, 1); 1);
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
return rv; return rv;
} }
} }
break; return 0;
} }
case NGHTTP2_WINDOW_UPDATE: case NGHTTP2_WINDOW_UPDATE:
if (frame->hd.stream_id == 0) { if (frame->hd.stream_id == 0) {
...@@ -2638,12 +2698,17 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2638,12 +2698,17 @@ static int session_after_frame_sent1(nghttp2_session *session) {
} else { } else {
rv = session_update_recv_connection_window_size(session, 0); rv = session_update_recv_connection_window_size(session, 0);
} }
} else {
nghttp2_stream *stream; if (nghttp2_is_fatal(rv)) {
return rv;
}
return 0;
}
stream = nghttp2_session_get_stream(session, frame->hd.stream_id); stream = nghttp2_session_get_stream(session, frame->hd.stream_id);
if (!stream) { if (!stream) {
break; return 0;
} }
stream->window_update_queued = 0; stream->window_update_queued = 0;
...@@ -2651,7 +2716,7 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2651,7 +2716,7 @@ static int session_after_frame_sent1(nghttp2_session *session) {
/* We don't have to send WINDOW_UPDATE if END_STREAM from peer /* We don't have to send WINDOW_UPDATE if END_STREAM from peer
is seen. */ is seen. */
if (stream->shut_flags & NGHTTP2_SHUT_RD) { if (stream->shut_flags & NGHTTP2_SHUT_RD) {
break; return 0;
} }
if (session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE) { if (session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE) {
...@@ -2659,84 +2724,15 @@ static int session_after_frame_sent1(nghttp2_session *session) { ...@@ -2659,84 +2724,15 @@ static int session_after_frame_sent1(nghttp2_session *session) {
} else { } else {
rv = session_update_recv_stream_window_size(session, stream, 0, 1); rv = session_update_recv_stream_window_size(session, stream, 0, 1);
} }
}
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
return rv; return rv;
} }
break;
default:
break;
}
return 0; return 0;
} else { default:
nghttp2_stream *stream;
nghttp2_data_aux_data *aux_data;
aux_data = &item->aux_data.data;
stream = nghttp2_session_get_stream(session, frame->hd.stream_id);
/* We update flow control window after a frame was completely
sent. This is possible because we choose payload length not to
exceed the window */
session->remote_window_size -= (int32_t)frame->hd.length;
if (stream) {
stream->remote_window_size -= (int32_t)frame->hd.length;
}
if (stream && aux_data->eof) {
rv = nghttp2_stream_detach_item(stream);
if (nghttp2_is_fatal(rv)) {
return rv;
}
/* Call on_frame_send_callback after
nghttp2_stream_detach_item(), so that application can issue
nghttp2_submit_data() in the callback. */
if (session->callbacks.on_frame_send_callback) {
rv = session_call_on_frame_send(session, frame);
if (nghttp2_is_fatal(rv)) {
return rv;
}
}
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
int stream_closed;
stream_closed =
(stream->shut_flags & NGHTTP2_SHUT_RDWR) == NGHTTP2_SHUT_RDWR;
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR);
rv = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
if (nghttp2_is_fatal(rv)) {
return rv;
}
/* stream may be NULL if it was closed */
if (stream_closed) {
stream = NULL;
}
}
return 0;
}
if (session->callbacks.on_frame_send_callback) {
rv = session_call_on_frame_send(session, frame);
if (nghttp2_is_fatal(rv)) {
return rv;
}
}
return 0; return 0;
} }
/* Unreachable */
assert(0);
return 0;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment