From: Artem Boldariev Date: Thu, 1 Jul 2021 09:04:47 +0000 (+0300) Subject: Move the code which calls server read callback into a separate func X-Git-Tag: v9.17.17~42^2~2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=094fcc10e7f4120554553036ad4e8eaea0efdb92;p=thirdparty%2Fbind9.git Move the code which calls server read callback into a separate func This commit moves the code which calls server read callback into a separate function to avoid code repetition. --- diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index f22f537d4ec..fe495b5db3e 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -210,6 +210,10 @@ static void call_pending_callbacks(isc__nm_http_pending_callbacks_t pending_callbacks, isc_result_t result); +static void +server_call_cb(isc_nmsocket_t *socket, isc_nm_http_session_t *session, + const isc_result_t result, isc_region_t *data); + static bool http_session_active(isc_nm_http_session_t *session) { REQUIRE(VALID_HTTP2_SESSION(session)); @@ -1986,12 +1990,26 @@ server_send_error_response(const isc_http_error_responses_t error, socket)); } +static void +server_call_cb(isc_nmsocket_t *socket, isc_nm_http_session_t *session, + const isc_result_t result, isc_region_t *data) { + isc_sockaddr_t addr; + isc_nmhandle_t *handle = NULL; + + REQUIRE(VALID_NMSOCK(socket)); + REQUIRE(VALID_HTTP2_SESSION(session)); + REQUIRE(socket->h2.cb != NULL); + + addr = isc_nmhandle_peeraddr(session->handle); + handle = isc__nmhandle_get(socket, &addr, NULL); + socket->h2.cb(handle, result, data, socket->h2.cbarg); + isc_nmhandle_detach(&handle); +} + static int server_on_request_recv(nghttp2_session *ngsession, isc_nm_http_session_t *session, isc_nmsocket_t *socket) { isc_result_t result; - isc_nmhandle_t *handle = NULL; - isc_sockaddr_t addr; isc_http_error_responses_t code = ISC_HTTP_ERROR_SUCCESS; isc_region_t data; @@ -2035,10 +2053,8 @@ server_on_request_recv(nghttp2_session *ngsession, ISC_UNREACHABLE(); } - addr = isc_nmhandle_peeraddr(session->handle); - handle = isc__nmhandle_get(socket, &addr, NULL); - socket->h2.cb(handle, ISC_R_SUCCESS, &data, socket->h2.cbarg); - isc_nmhandle_detach(&handle); + server_call_cb(socket, session, ISC_R_SUCCESS, &data); + return (0); error: @@ -2608,9 +2624,6 @@ isc__nm_async_httpclose(isc__networker_t *worker, isc__netievent_t *ev0) { static void failed_httpstream_read_cb(isc_nmsocket_t *sock, isc_result_t result, isc_nm_http_session_t *session) { - isc_nmhandle_t *handle = NULL; - isc_sockaddr_t addr; - REQUIRE(VALID_NMSOCK(sock)); INSIST(sock->type == isc_nm_httpsocket); @@ -2623,12 +2636,8 @@ failed_httpstream_read_cb(isc_nmsocket_t *sock, isc_result_t result, (void)nghttp2_submit_rst_stream( session->ngsession, NGHTTP2_FLAG_END_STREAM, sock->h2.stream_id, NGHTTP2_REFUSED_STREAM); - addr = isc_nmhandle_peeraddr(session->handle); - handle = isc__nmhandle_get(sock, &addr, NULL); - sock->h2.cb(handle, result, - &(isc_region_t){ sock->h2.buf, sock->h2.bufsize }, - sock->h2.cbarg); - isc_nmhandle_detach(&handle); + server_call_cb(sock, session, result, + &(isc_region_t){ sock->h2.buf, sock->h2.bufsize }); } static void