Refactor session_prep_frame to eliminate framerv

This commit is contained in:
Tatsuhiro Tsujikawa 2015-02-12 22:58:43 +09:00
parent 115d7133a0
commit 57a50f981b
1 changed files with 41 additions and 55 deletions

View File

@ -1647,7 +1647,6 @@ static size_t session_estimate_headers_payload(nghttp2_session *session,
*/ */
static int session_prep_frame(nghttp2_session *session, static int session_prep_frame(nghttp2_session *session,
nghttp2_outbound_item *item) { nghttp2_outbound_item *item) {
int framerv = 0;
int rv; int rv;
nghttp2_frame *frame; nghttp2_frame *frame;
nghttp2_mem *mem; nghttp2_mem *mem;
@ -1724,21 +1723,21 @@ static int session_prep_frame(nghttp2_session *session,
} }
} }
framerv = nghttp2_frame_pack_headers( rv = nghttp2_frame_pack_headers(&session->aob.framebufs, &frame->headers,
&session->aob.framebufs, &frame->headers, &session->hd_deflater); &session->hd_deflater);
if (framerv < 0) { if (rv != 0) {
return framerv; return rv;
} }
DEBUGF(fprintf(stderr, DEBUGF(fprintf(stderr,
"send: before padding, HEADERS serialized in %zd bytes\n", "send: before padding, HEADERS serialized in %zd bytes\n",
nghttp2_bufs_len(&session->aob.framebufs))); nghttp2_bufs_len(&session->aob.framebufs)));
framerv = session_headers_add_pad(session, frame); rv = session_headers_add_pad(session, frame);
if (framerv < 0) { if (rv != 0) {
return framerv; return rv;
} }
DEBUGF(fprintf(stderr, "send: HEADERS finally serialized in %zd bytes\n", DEBUGF(fprintf(stderr, "send: HEADERS finally serialized in %zd bytes\n",
@ -1752,11 +1751,7 @@ static int session_prep_frame(nghttp2_session *session,
} }
/* PRIORITY frame can be sent at any time and to any stream /* PRIORITY frame can be sent at any time and to any stream
ID. */ ID. */
framerv = nghttp2_frame_pack_priority(&session->aob.framebufs, nghttp2_frame_pack_priority(&session->aob.framebufs, &frame->priority);
&frame->priority);
if (framerv < 0) {
return framerv;
}
/* Peer can send PRIORITY frame against idle stream to create /* Peer can send PRIORITY frame against idle stream to create
"anchor" in dependency tree. Only client can do this in "anchor" in dependency tree. Only client can do this in
@ -1768,17 +1763,14 @@ static int session_prep_frame(nghttp2_session *session,
if (session_is_closing(session)) { if (session_is_closing(session)) {
return NGHTTP2_ERR_SESSION_CLOSING; return NGHTTP2_ERR_SESSION_CLOSING;
} }
framerv = nghttp2_frame_pack_rst_stream(&session->aob.framebufs, nghttp2_frame_pack_rst_stream(&session->aob.framebufs,
&frame->rst_stream); &frame->rst_stream);
if (framerv < 0) {
return framerv;
}
break; break;
case NGHTTP2_SETTINGS: { case NGHTTP2_SETTINGS: {
framerv = nghttp2_frame_pack_settings(&session->aob.framebufs, rv = nghttp2_frame_pack_settings(&session->aob.framebufs,
&frame->settings); &frame->settings);
if (framerv < 0) { if (rv != 0) {
return framerv; return rv;
} }
break; break;
} }
@ -1823,14 +1815,14 @@ static int session_prep_frame(nghttp2_session *session,
assert(stream); assert(stream);
framerv = nghttp2_frame_pack_push_promise( rv = nghttp2_frame_pack_push_promise(
&session->aob.framebufs, &frame->push_promise, &session->hd_deflater); &session->aob.framebufs, &frame->push_promise, &session->hd_deflater);
if (framerv < 0) { if (rv != 0) {
return framerv; return rv;
} }
framerv = session_headers_add_pad(session, frame); rv = session_headers_add_pad(session, frame);
if (framerv < 0) { if (rv != 0) {
return framerv; return rv;
} }
break; break;
@ -1839,28 +1831,21 @@ static int session_prep_frame(nghttp2_session *session,
if (session_is_closing(session)) { if (session_is_closing(session)) {
return NGHTTP2_ERR_SESSION_CLOSING; return NGHTTP2_ERR_SESSION_CLOSING;
} }
framerv = nghttp2_frame_pack_ping(&session->aob.framebufs, &frame->ping); nghttp2_frame_pack_ping(&session->aob.framebufs, &frame->ping);
if (framerv < 0) {
return framerv;
}
break; break;
case NGHTTP2_WINDOW_UPDATE: { case NGHTTP2_WINDOW_UPDATE: {
rv = session_predicate_window_update_send(session, frame->hd.stream_id); rv = session_predicate_window_update_send(session, frame->hd.stream_id);
if (rv != 0) { if (rv != 0) {
return rv; return rv;
} }
framerv = nghttp2_frame_pack_window_update(&session->aob.framebufs, nghttp2_frame_pack_window_update(&session->aob.framebufs,
&frame->window_update); &frame->window_update);
if (framerv < 0) {
return framerv;
}
break; break;
} }
case NGHTTP2_GOAWAY: case NGHTTP2_GOAWAY:
framerv = rv = nghttp2_frame_pack_goaway(&session->aob.framebufs, &frame->goaway);
nghttp2_frame_pack_goaway(&session->aob.framebufs, &frame->goaway); if (rv != 0) {
if (framerv < 0) { return rv;
return framerv;
} }
session->local_last_stream_id = frame->goaway.last_stream_id; session->local_last_stream_id = frame->goaway.last_stream_id;
@ -1915,10 +1900,9 @@ static int session_prep_frame(nghttp2_session *session,
return NGHTTP2_ERR_DEFERRED; return NGHTTP2_ERR_DEFERRED;
} }
framerv = rv = nghttp2_session_pack_data(session, &session->aob.framebufs,
nghttp2_session_pack_data(session, &session->aob.framebufs, next_readmax, frame, &item->aux_data.data);
next_readmax, frame, &item->aux_data.data); if (rv == NGHTTP2_ERR_DEFERRED) {
if (framerv == NGHTTP2_ERR_DEFERRED) {
rv = nghttp2_stream_defer_item(stream, NGHTTP2_STREAM_FLAG_DEFERRED_USER, rv = nghttp2_stream_defer_item(stream, NGHTTP2_STREAM_FLAG_DEFERRED_USER,
session); session);
@ -1930,7 +1914,7 @@ static int session_prep_frame(nghttp2_session *session,
active_outbound_item_reset(&session->aob, mem); active_outbound_item_reset(&session->aob, mem);
return NGHTTP2_ERR_DEFERRED; return NGHTTP2_ERR_DEFERRED;
} }
if (framerv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) {
rv = nghttp2_stream_detach_item(stream, session); rv = nghttp2_stream_detach_item(stream, session);
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
@ -1939,19 +1923,21 @@ static int session_prep_frame(nghttp2_session *session,
rv = nghttp2_session_add_rst_stream(session, frame->hd.stream_id, rv = nghttp2_session_add_rst_stream(session, frame->hd.stream_id,
NGHTTP2_INTERNAL_ERROR); NGHTTP2_INTERNAL_ERROR);
if (rv != 0) {
return rv;
}
return framerv;
}
if (framerv < 0) {
rv = nghttp2_stream_detach_item(stream, session);
if (nghttp2_is_fatal(rv)) { if (nghttp2_is_fatal(rv)) {
return rv; return rv;
} }
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
}
if (rv != 0) {
int rv2;
return framerv; rv2 = nghttp2_stream_detach_item(stream, session);
if (nghttp2_is_fatal(rv2)) {
return rv2;
}
return rv;
} }
return 0; return 0;
} }