From 2ae0f9d00a81f97bde4830d71d75da45265b2e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Fri, 26 Jul 2019 18:28:05 +0200 Subject: [PATCH] isc__nm_in_netthread --- lib/isc/include/isc/netmgr.h | 1 + lib/isc/netmgr/netmgr-int.h | 4 ++++ lib/isc/netmgr/netmgr.c | 5 +++++ lib/isc/netmgr/udp.c | 6 +++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/isc/include/isc/netmgr.h b/lib/isc/include/isc/netmgr.h index a8dbbfc86f..a69d927e60 100644 --- a/lib/isc/include/isc/netmgr.h +++ b/lib/isc/include/isc/netmgr.h @@ -47,6 +47,7 @@ isc_nm_attach(isc_nm_t *mgr, isc_nm_t **dst); void isc_nm_detach(isc_nm_t **mgr0); + /* * isc_nm_freehandle frees a handle, releasing resources */ diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 2e8d15e25d..d3e3f80234 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -294,6 +294,10 @@ struct isc_nmsocket { int isc__nm_tid(void); +/* Are we in network thread? */ +bool +isc__nm_in_netthread(void); + void isc__nmhandle_free(isc_nmsocket_t *socket, isc_nmhandle_t *handle); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 13a16fec69..532dfaf7fc 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -68,6 +68,11 @@ isc__nm_tid() { return (isc__nm_tid_v); } +bool +isc__nm_in_netthread() { + return (isc__nm_tid_v >= 0); +} + /* * isc_nm_start creates and starts a network manager, with `workers` workers. */ diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index f1d429388d..9a21ed065b 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -117,7 +117,7 @@ isc_nm_udp_stoplistening(isc_nmsocket_t *socket) { INSIST(VALID_NMSOCK(socket)); /* We can't be launched from network thread */ - INSIST(isc__nm_tid() == ISC_NETMGR_TID_UNKNOWN); + REQUIRE(!isc__nm_in_netthread()); INSIST(socket->type == isc_nm_udplistener); for (i = 0; i < socket->nchildren; i++) { @@ -128,6 +128,10 @@ isc_nm_udp_stoplistening(isc_nmsocket_t *socket) { isc__nm_enqueue_ievent(&socket->mgr->workers[i], (isc__netievent_t*) ievent); } + /* + * XXXWPK TODO wait for everything to clean up, we have a race here + * clients think that we stopped listening and we still might issue callbacks + */ } /*