From: Evan Hunt Date: Thu, 16 Apr 2020 02:26:49 +0000 (-0700) Subject: change the signature of recv callbacks to include a result code X-Git-Tag: v9.17.3~49^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75c985c07f2208d434977b27fe3eb41a433924d7;p=thirdparty%2Fbind9.git change the signature of recv callbacks to include a result code this will allow recv event handlers to distinguish between cases in which the region is NULL because of error, shutdown, or cancelation. --- diff --git a/lib/isc/include/isc/netmgr.h b/lib/isc/include/isc/netmgr.h index 0e2db629ea5..4cb5b122896 100644 --- a/lib/isc/include/isc/netmgr.h +++ b/lib/isc/include/isc/netmgr.h @@ -122,26 +122,27 @@ isc_nmhandle_netmgr(isc_nmhandle_t *handle); * Return a pointer to the netmgr object for the given handle. */ -typedef void (*isc_nm_recv_cb_t)(isc_nmhandle_t *handle, isc_region_t *region, - void *cbarg); +typedef void (*isc_nm_recv_cb_t)(isc_nmhandle_t *handle, isc_result_t eresult, + isc_region_t *region, void *cbarg); /*%< * Callback function to be used when receiving a packet. * * 'handle' the handle that can be used to send back the answer. - * 'region' contains the received data. It will be freed after - * return by caller. + * 'eresult' the result of the event. + * 'region' contains the received data, if any. It will be freed + * after return by caller. * 'cbarg' the callback argument passed to isc_nm_listenudp(), * isc_nm_listentcpdns(), or isc_nm_read(). */ -typedef void (*isc_nm_cb_t)(isc_nmhandle_t *handle, isc_result_t result, +typedef void (*isc_nm_cb_t)(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg); /*%< * Callback function for other network completion events (send, connect, * accept). * * 'handle' the handle on which the event took place. - * 'result' the result of the event. + * 'eresult' the result of the event. * 'cbarg' the callback argument passed to isc_nm_send(), * isc_nm_tcp_connect(), or isc_nm_listentcp() */ diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 48c03148207..f38f31070bf 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -582,7 +582,8 @@ readtimeout_cb(uv_timer_t *handle) { isc_quota_detach(&sock->quota); } if (sock->rcb.recv != NULL) { - sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg); + sock->rcb.recv(sock->tcphandle, ISC_R_TIMEDOUT, NULL, + sock->rcbarg); } } @@ -716,7 +717,8 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { .length = nread }; if (sock->rcb.recv != NULL) { - sock->rcb.recv(sock->tcphandle, ®ion, sock->rcbarg); + sock->rcb.recv(sock->tcphandle, ISC_R_SUCCESS, ®ion, + sock->rcbarg); } sock->read_timeout = (atomic_load(&sock->keepalive) @@ -741,7 +743,7 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { */ if (sock->rcb.recv != NULL) { isc__nm_incstats(sock->mgr, sock->statsindex[STATID_RECVFAIL]); - sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg); + sock->rcb.recv(sock->tcphandle, ISC_R_EOF, NULL, sock->rcbarg); } /* @@ -1076,7 +1078,8 @@ isc__nm_tcp_shutdown(isc_nmsocket_t *sock) { if (sock->type == isc_nm_tcpsocket && sock->tcphandle != NULL && sock->rcb.recv != NULL) { - sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg); + sock->rcb.recv(sock->tcphandle, ISC_R_CANCELED, NULL, + sock->rcbarg); } } diff --git a/lib/isc/netmgr/tcpdns.c b/lib/isc/netmgr/tcpdns.c index c7d23e96a99..19a31870f2d 100644 --- a/lib/isc/netmgr/tcpdns.c +++ b/lib/isc/netmgr/tcpdns.c @@ -38,7 +38,8 @@ */ static void -dnslisten_readcb(isc_nmhandle_t *handle, isc_region_t *region, void *arg); +dnslisten_readcb(isc_nmhandle_t *handle, isc_result_t eresult, + isc_region_t *region, void *arg); static void resume_processing(void *arg); @@ -187,7 +188,7 @@ processbuffer(isc_nmsocket_t *dnssock, isc_nmhandle_t **handlep) { if (listener != NULL && listener->rcb.recv != NULL) { listener->rcb.recv( - dnshandle, + dnshandle, ISC_R_SUCCESS, &(isc_region_t){ .base = dnssock->buf + 2, .length = len }, listener->rcbarg); @@ -212,7 +213,8 @@ processbuffer(isc_nmsocket_t *dnssock, isc_nmhandle_t **handlep) { * a complete DNS packet and, if so - call the callback */ static void -dnslisten_readcb(isc_nmhandle_t *handle, isc_region_t *region, void *arg) { +dnslisten_readcb(isc_nmhandle_t *handle, isc_result_t eresult, + isc_region_t *region, void *arg) { isc_nmsocket_t *dnssock = (isc_nmsocket_t *)arg; unsigned char *base = NULL; bool done = false; @@ -222,9 +224,10 @@ dnslisten_readcb(isc_nmhandle_t *handle, isc_region_t *region, void *arg) { REQUIRE(VALID_NMHANDLE(handle)); REQUIRE(dnssock->tid == isc_nm_tid()); - if (region == NULL) { + if (region == NULL || eresult != ISC_R_SUCCESS) { /* Connection closed */ isc_nmhandle_unref(handle); + dnssock->result = eresult; if (dnssock->self != NULL) { isc__nmsocket_detach(&dnssock->self); } diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index d37c1c47653..b2b8166afb6 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -364,7 +364,7 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, region.length = nrecv; INSIST(sock->rcb.recv != NULL); - sock->rcb.recv(nmhandle, ®ion, sock->rcbarg); + sock->rcb.recv(nmhandle, ISC_R_SUCCESS, ®ion, sock->rcbarg); if (free_buf) { isc__nm_free_uvbuf(sock, buf); } diff --git a/lib/ns/client.c b/lib/ns/client.c index 1c8df4b0fb0..00badb4ac56 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -1620,7 +1620,8 @@ ns__client_put_cb(void *client0) { * or tcpmsg (TCP case). */ void -ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) { +ns__client_request(isc_nmhandle_t *handle, isc_result_t eresult, + isc_region_t *region, void *arg) { ns_client_t *client; bool newclient = false; ns_clientmgr_t *mgr; @@ -1644,6 +1645,8 @@ ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) { #endif /* ifdef HAVE_DNSTAP */ ifp = (ns_interface_t *)arg; + UNUSED(eresult); + mgr = ifp->clientmgr; if (mgr == NULL) { /* The interface was shut down in the meantime, just bail */ diff --git a/lib/ns/include/ns/client.h b/lib/ns/include/ns/client.h index 74c435b0c61..bc6ec751e97 100644 --- a/lib/ns/include/ns/client.h +++ b/lib/ns/include/ns/client.h @@ -468,7 +468,8 @@ ns_client_addopt(ns_client_t *client, dns_message_t *message, */ void -ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg); +ns__client_request(isc_nmhandle_t *handle, isc_result_t eresult, + isc_region_t *region, void *arg); /*%< * Handle client requests.