mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-03 13:59:27 -04:00
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.
This commit is contained in:
parent
5191ec8f86
commit
75c985c07f
6 changed files with 28 additions and 17 deletions
|
|
@ -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()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue