Refactor predicate functions

This commit is contained in:
Tatsuhiro Tsujikawa 2017-04-26 22:31:43 +09:00
parent 66baa7dc25
commit 2358a2137a
1 changed files with 14 additions and 17 deletions

View File

@ -1524,14 +1524,15 @@ static int session_predicate_response_headers_send(nghttp2_session *session,
if (nghttp2_session_is_my_stream_id(session, stream->stream_id)) { if (nghttp2_session_is_my_stream_id(session, stream->stream_id)) {
return NGHTTP2_ERR_INVALID_STREAM_ID; return NGHTTP2_ERR_INVALID_STREAM_ID;
} }
if (stream->state == NGHTTP2_STREAM_OPENING) { switch (stream->state) {
case NGHTTP2_STREAM_OPENING:
return 0; return 0;
} case NGHTTP2_STREAM_CLOSING:
if (stream->state == NGHTTP2_STREAM_CLOSING) {
return NGHTTP2_ERR_STREAM_CLOSING; return NGHTTP2_ERR_STREAM_CLOSING;
} default:
return NGHTTP2_ERR_INVALID_STREAM_STATE; return NGHTTP2_ERR_INVALID_STREAM_STATE;
} }
}
/* /*
* This function checks HEADERS for reserved stream can be sent. The * This function checks HEADERS for reserved stream can be sent. The
@ -1573,9 +1574,6 @@ session_predicate_push_response_headers_send(nghttp2_session *session,
if (stream->state != NGHTTP2_STREAM_RESERVED) { if (stream->state != NGHTTP2_STREAM_RESERVED) {
return NGHTTP2_ERR_PROTO; return NGHTTP2_ERR_PROTO;
} }
if (stream->state == NGHTTP2_STREAM_CLOSING) {
return NGHTTP2_ERR_STREAM_CLOSING;
}
if (session->goaway_flags & NGHTTP2_GOAWAY_RECV) { if (session->goaway_flags & NGHTTP2_GOAWAY_RECV) {
return NGHTTP2_ERR_START_STREAM_NOT_ALLOWED; return NGHTTP2_ERR_START_STREAM_NOT_ALLOWED;
} }
@ -1610,20 +1608,19 @@ static int session_predicate_headers_send(nghttp2_session *session,
return rv; return rv;
} }
assert(stream); assert(stream);
switch (stream->state) {
case NGHTTP2_STREAM_OPENED:
return 0;
case NGHTTP2_STREAM_CLOSING:
return NGHTTP2_ERR_STREAM_CLOSING;
default:
if (nghttp2_session_is_my_stream_id(session, stream->stream_id)) { if (nghttp2_session_is_my_stream_id(session, stream->stream_id)) {
if (stream->state == NGHTTP2_STREAM_CLOSING) {
return NGHTTP2_ERR_STREAM_CLOSING;
}
return 0; return 0;
} }
if (stream->state == NGHTTP2_STREAM_OPENED) {
return 0;
}
if (stream->state == NGHTTP2_STREAM_CLOSING) {
return NGHTTP2_ERR_STREAM_CLOSING;
}
return NGHTTP2_ERR_INVALID_STREAM_STATE; return NGHTTP2_ERR_INVALID_STREAM_STATE;
} }
}
/* /*
* This function checks PUSH_PROMISE frame |frame| with the |stream| * This function checks PUSH_PROMISE frame |frame| with the |stream|