From 9cb8754d09a37e5bd52f0c17045292852dd7a9fe Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 26 Dec 2013 00:23:07 +0900 Subject: [PATCH] Rename nghttp2_session_fail_session as nghttp2_session_terminate_session --- examples/libevent-client.c | 2 +- lib/includes/nghttp2/nghttp2.h | 14 +++++++++++--- lib/nghttp2_session.c | 25 ++++++++++++++----------- src/HttpServer.cc | 6 +++--- src/HttpServer.h | 2 +- src/nghttp.cc | 4 ++-- src/shrpx_http2_session.cc | 6 +++--- src/shrpx_http2_session.h | 2 +- src/shrpx_http2_upstream.cc | 6 +++--- src/shrpx_http2_upstream.h | 2 +- 10 files changed, 40 insertions(+), 29 deletions(-) diff --git a/examples/libevent-client.c b/examples/libevent-client.c index 7d31c081..1558f761 100644 --- a/examples/libevent-client.c +++ b/examples/libevent-client.c @@ -250,7 +250,7 @@ static int on_stream_close_callback(nghttp2_session *session, if(session_data->stream_data->stream_id == stream_id) { fprintf(stderr, "Stream %d closed with error_code=%d\n", stream_id, error_code); - rv = nghttp2_session_fail_session(session, NGHTTP2_NO_ERROR); + rv = nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR); if(rv != 0) { return NGHTTP2_ERR_CALLBACK_FAILURE; } diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 20582265..d53f5444 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -1687,7 +1687,15 @@ int32_t nghttp2_session_get_effective_local_window_size /** * @function * - * Submits GOAWAY frame with the given |error_code|. + * Signals the session so that the connection should be terminated. + * + * GOAWAY frame with the given |error_code| will be submitted if it + * has not been transmitted. After the transmission, both + * `nghttp2_session_want_read()` and `nghttp2_session_want_write()` + * return 0. If GOAWAY frame has already transmitted at the time when + * this function is invoked, `nghttp2_session_want_read()` and + * `nghttp2_session_want_write()` returns 0 immediately after this + * function succeeds. * * This function should be called when the connection should be * terminated after sending GOAWAY. If the remaining streams should be @@ -1699,8 +1707,8 @@ int32_t nghttp2_session_get_effective_local_window_size * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. */ -int nghttp2_session_fail_session(nghttp2_session *session, - nghttp2_error_code error_code); +int nghttp2_session_terminate_session(nghttp2_session *session, + nghttp2_error_code error_code); /** * @function diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 2814afe3..5f8714c9 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -80,8 +80,8 @@ static int32_t nghttp2_pushed_stream_pri(nghttp2_stream *stream) (int32_t)NGHTTP2_PRI_LOWEST : stream->pri + 1; } -int nghttp2_session_fail_session(nghttp2_session *session, - nghttp2_error_code error_code) +int nghttp2_session_terminate_session(nghttp2_session *session, + nghttp2_error_code error_code) { if(session->goaway_flags & NGHTTP2_GOAWAY_FAIL_ON_SEND) { return 0; @@ -1674,8 +1674,8 @@ int nghttp2_session_send(nghttp2_session *session) if(framebuflen == NGHTTP2_ERR_HEADER_COMP) { /* If header compression error occurred, should terminiate connection. */ - framebuflen = nghttp2_session_fail_session(session, - NGHTTP2_INTERNAL_ERROR); + framebuflen = nghttp2_session_terminate_session + (session, NGHTTP2_INTERNAL_ERROR); } if(nghttp2_is_fatal(framebuflen)) { return framebuflen; @@ -1843,7 +1843,7 @@ static int nghttp2_session_handle_parse_error(nghttp2_session *session, return NGHTTP2_ERR_CALLBACK_FAILURE; } } - return nghttp2_session_fail_session(session, error_code); + return nghttp2_session_terminate_session(session, error_code); } static int nghttp2_session_handle_invalid_stream @@ -1879,7 +1879,7 @@ static int nghttp2_session_handle_invalid_connection return NGHTTP2_ERR_CALLBACK_FAILURE; } } - return nghttp2_session_fail_session(session, error_code); + return nghttp2_session_terminate_session(session, error_code); } int nghttp2_session_on_request_headers_received(nghttp2_session *session, @@ -2984,7 +2984,7 @@ int nghttp2_session_on_data_received(nghttp2_session *session, /* The spec says that if a DATA frame is received whose stream ID is 0, the recipient MUST respond with a connection error of type PROTOCOL_ERROR. */ - return nghttp2_session_fail_session(session, NGHTTP2_PROTOCOL_ERROR); + return nghttp2_session_terminate_session(session, NGHTTP2_PROTOCOL_ERROR); } stream = nghttp2_session_get_stream(session, stream_id); if(!stream) { @@ -2995,7 +2995,7 @@ int nghttp2_session_on_data_received(nghttp2_session *session, } if(stream->state == NGHTTP2_STREAM_RESERVED) { /* reserved and receiving DATA is connection error */ - return nghttp2_session_fail_session(session, NGHTTP2_PROTOCOL_ERROR); + return nghttp2_session_terminate_session(session, NGHTTP2_PROTOCOL_ERROR); } if(stream->shut_flags & NGHTTP2_SHUT_RD) { /* half closed (remote): from the spec: @@ -3012,7 +3012,8 @@ int nghttp2_session_on_data_received(nghttp2_session *session, is broken, it may send lots of DATA frames and we will send RST_STREAM for each of them, which is bad. So we just close the connection here. */ - return nghttp2_session_fail_session(session, NGHTTP2_PROTOCOL_ERROR); + return nghttp2_session_terminate_session(session, + NGHTTP2_PROTOCOL_ERROR); } return 0; } @@ -3032,7 +3033,8 @@ int nghttp2_session_on_data_received(nghttp2_session *session, peer is broken, it may send lots of DATA frames and we will send RST_STREAM for each of them, which is bad. So we just close the connection here. */ - return nghttp2_session_fail_session(session, NGHTTP2_PROTOCOL_ERROR); + return nghttp2_session_terminate_session(session, + NGHTTP2_PROTOCOL_ERROR); } } else if(stream->state != NGHTTP2_STREAM_CLOSING) { /* It is OK if this is remote peer initiated stream and we did @@ -3160,7 +3162,8 @@ static int nghttp2_session_update_recv_connection_window_size rv = adjust_recv_window_size(&session->recv_window_size, delta_size, session->local_window_size); if(rv != 0) { - return nghttp2_session_fail_session(session, NGHTTP2_FLOW_CONTROL_ERROR); + return nghttp2_session_terminate_session(session, + NGHTTP2_FLOW_CONTROL_ERROR); } if(!(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_CONNECTION_WINDOW_UPDATE)) { diff --git a/src/HttpServer.cc b/src/HttpServer.cc index e4ae1770..e4f5918b 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -352,7 +352,7 @@ namespace { void settings_timeout_cb(evutil_socket_t fd, short what, void *arg) { auto hd = reinterpret_cast(arg); - hd->fail_session(NGHTTP2_SETTINGS_TIMEOUT); + hd->terminate_session(NGHTTP2_SETTINGS_TIMEOUT); hd->on_write(); } } // namespace @@ -581,9 +581,9 @@ void Http2Handler::remove_settings_timer() } } -void Http2Handler::fail_session(nghttp2_error_code error_code) +void Http2Handler::terminate_session(nghttp2_error_code error_code) { - nghttp2_session_fail_session(session_, error_code); + nghttp2_session_terminate_session(session_, error_code); } namespace { diff --git a/src/HttpServer.h b/src/HttpServer.h index 341cb727..6eb26164 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -119,7 +119,7 @@ public: size_t get_left_connhd_len() const; void set_left_connhd_len(size_t left); void remove_settings_timer(); - void fail_session(nghttp2_error_code error_code); + void terminate_session(nghttp2_error_code error_code); private: std::map> id2req_; int64_t session_id_; diff --git a/src/nghttp.cc b/src/nghttp.cc index 0989aaae..f6d3c35d 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -1084,7 +1084,7 @@ namespace { void settings_timeout_cb(evutil_socket_t fd, short what, void *arg) { auto client = get_session(arg); - nghttp2_session_fail_session(client->session, NGHTTP2_SETTINGS_TIMEOUT); + nghttp2_session_terminate_session(client->session, NGHTTP2_SETTINGS_TIMEOUT); client->on_write(); } } // namespace @@ -1181,7 +1181,7 @@ int on_stream_close_callback (*itr).second->record_complete_time(); ++client->complete; if(client->all_requests_processed()) { - nghttp2_session_fail_session(session, NGHTTP2_NO_ERROR); + nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR); } } return 0; diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 10cebe27..c7ea40a3 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -760,7 +760,7 @@ void settings_timeout_cb(evutil_socket_t fd, short what, void *arg) { auto http2session = reinterpret_cast(arg); SSLOG(INFO, http2session) << "SETTINGS timeout"; - if(http2session->fail_session(NGHTTP2_SETTINGS_TIMEOUT) != 0) { + if(http2session->terminate_session(NGHTTP2_SETTINGS_TIMEOUT) != 0) { http2session->disconnect(); return; } @@ -1290,10 +1290,10 @@ void Http2Session::set_state(int state) state_ = state; } -int Http2Session::fail_session(nghttp2_error_code error_code) +int Http2Session::terminate_session(nghttp2_error_code error_code) { int rv; - rv = nghttp2_session_fail_session(session_, error_code); + rv = nghttp2_session_terminate_session(session_, error_code); if(rv != 0) { return -1; } diff --git a/src/shrpx_http2_session.h b/src/shrpx_http2_session.h index 8622bfda..868e8002 100644 --- a/src/shrpx_http2_session.h +++ b/src/shrpx_http2_session.h @@ -74,7 +74,7 @@ public: // |dconn|. int submit_window_update(Http2DownstreamConnection *dconn, int32_t amount); - int fail_session(nghttp2_error_code error_code); + int terminate_session(nghttp2_error_code error_code); nghttp2_session* get_session() const; diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 468be624..5b16e919 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -177,7 +177,7 @@ void settings_timeout_cb(evutil_socket_t fd, short what, void *arg) { auto upstream = reinterpret_cast(arg); ULOG(INFO, upstream) << "SETTINGS timeout"; - if(upstream->fail_session(NGHTTP2_SETTINGS_TIMEOUT) != 0) { + if(upstream->terminate_session(NGHTTP2_SETTINGS_TIMEOUT) != 0) { delete upstream->get_client_handler(); return; } @@ -813,10 +813,10 @@ int Http2Upstream::window_update(Downstream *downstream, return 0; } -int Http2Upstream::fail_session(nghttp2_error_code error_code) +int Http2Upstream::terminate_session(nghttp2_error_code error_code) { int rv; - rv = nghttp2_session_fail_session(session_, error_code); + rv = nghttp2_session_terminate_session(session_, error_code); if(rv != 0) { return -1; } diff --git a/src/shrpx_http2_upstream.h b/src/shrpx_http2_upstream.h index e88f726c..ca0cb3c1 100644 --- a/src/shrpx_http2_upstream.h +++ b/src/shrpx_http2_upstream.h @@ -61,7 +61,7 @@ public: // To send WINDOW_UPDATE for a connection, specify nullptr to // |downstream|. int window_update(Downstream *downstream, int32_t window_size_increment); - int fail_session(nghttp2_error_code error_code); + int terminate_session(nghttp2_error_code error_code); int error_reply(Downstream *downstream, unsigned int status_code); virtual void pause_read(IOCtrlReason reason);