From 1baffb6ff5d4844523f7a86cd62d2f59dd9909a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 23 Mar 2023 22:16:47 +0100 Subject: [PATCH] Convert canceling UDP socket to to isc_async callback Simplify the canceling of the UDP socket by using the isc_async API from the loopmgr instead of using the asychronous netievent mechanism in the netmgr. --- lib/isc/netmgr/netmgr-int.h | 12 ----------- lib/isc/netmgr/netmgr.c | 3 --- lib/isc/netmgr/udp.c | 43 +++++++++++++++---------------------- 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 345f477295..c7f18eb0ff 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -250,8 +250,6 @@ struct isc_nmhandle { }; typedef enum isc__netievent_type { - netievent_udpcancel, - netievent_tcpaccept, netievent_tlsclose, @@ -1231,12 +1229,6 @@ isc__nm_udp_settimeout(isc_nmhandle_t *handle, uint32_t timeout); * Set or clear the recv timeout for the UDP socket associated with 'handle'. */ -void -isc__nm_async_udpcancel(isc__networker_t *worker, isc__netievent_t *ev0); -/*%< - * Callback handlers for asynchronous UDP events (listen, stoplisten, send). - */ - void isc__nm_tcp_send(isc_nmhandle_t *handle, const isc_region_t *region, isc_nm_cb_t cb, void *cbarg); @@ -1703,8 +1695,6 @@ NETIEVENT_SOCKET_REQ_TYPE(tlssend); NETIEVENT_SOCKET_REQ_RESULT_TYPE(sendcb); -NETIEVENT_SOCKET_HANDLE_TYPE(udpcancel); - NETIEVENT_SOCKET_QUOTA_TYPE(tcpaccept); NETIEVENT_SOCKET_TYPE(streamdnsread); @@ -1729,8 +1719,6 @@ NETIEVENT_SOCKET_REQ_DECL(tlssend); NETIEVENT_SOCKET_REQ_RESULT_DECL(sendcb); -NETIEVENT_SOCKET_HANDLE_DECL(udpcancel); - NETIEVENT_SOCKET_QUOTA_DECL(tcpaccept); NETIEVENT_SOCKET_DECL(streamdnsread); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index ba4a712b01..6059c7850b 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -439,8 +439,6 @@ process_netievent(void *arg) { isc__networker_t *worker = ievent->worker; switch (ievent->type) { - NETIEVENT_CASE(udpcancel); - NETIEVENT_CASE(tcpaccept); NETIEVENT_CASE(tlssend); @@ -483,7 +481,6 @@ isc__nm_put_netievent(isc__networker_t *worker, void *ievent) { NETIEVENT_SOCKET_DEF(tlsclose); NETIEVENT_SOCKET_DEF(tlsconnect); NETIEVENT_SOCKET_DEF(tlsdobio); -NETIEVENT_SOCKET_HANDLE_DEF(udpcancel); #ifdef HAVE_LIBNGHTTP2 NETIEVENT_SOCKET_REQ_DEF(httpsend); diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index a443a1df40..0ab10c5253 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -1064,36 +1064,27 @@ isc__nm_udp_shutdown(isc_nmsocket_t *sock) { isc__nmsocket_prep_destroy(sock); } -void -isc__nm_udp_cancelread(isc_nmhandle_t *handle) { - isc_nmsocket_t *sock = NULL; - isc__netievent_udpcancel_t *ievent = NULL; - - REQUIRE(VALID_NMHANDLE(handle)); - - sock = handle->sock; +static void +udp_cancelread_cb(void *arg) { + isc_nmsocket_t *sock = arg; REQUIRE(VALID_NMSOCK(sock)); - REQUIRE(sock->type == isc_nm_udpsocket); - - ievent = isc__nm_get_netievent_udpcancel(sock->worker, sock, handle); - - isc__nm_enqueue_ievent(sock->worker, (isc__netievent_t *)ievent); -} - -void -isc__nm_async_udpcancel(isc__networker_t *worker, isc__netievent_t *ev0) { - isc__netievent_udpcancel_t *ievent = (isc__netievent_udpcancel_t *)ev0; - isc_nmsocket_t *sock = NULL; - - UNUSED(worker); - - REQUIRE(VALID_NMSOCK(ievent->sock)); - - sock = ievent->sock; - REQUIRE(sock->tid == isc_tid()); REQUIRE(atomic_load(&sock->client)); isc__nm_failed_read_cb(sock, ISC_R_EOF, false); + isc__nmsocket_detach(&sock); +} + +void +isc__nm_udp_cancelread(isc_nmhandle_t *handle) { + REQUIRE(VALID_NMHANDLE(handle)); + + isc_nmsocket_t *sock = handle->sock; + + REQUIRE(VALID_NMSOCK(sock)); + REQUIRE(sock->type == isc_nm_udpsocket); + + isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL }); + isc_async_run(sock->worker->loop, udp_cancelread_cb, sock); }