From 7ddc49d66a00a4c8b9f384a123c72dc8b64bae25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 23 Mar 2023 23:34:12 +0100 Subject: [PATCH] Convert canceling StreamDNS socket to to isc_async callback Simplify the canceling of the StreamDNS 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 | 9 --------- lib/isc/netmgr/netmgr.c | 4 ---- lib/isc/netmgr/streamdns.c | 29 +++++++++++------------------ 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 3ab5e11583..70cf577404 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_streamdnscancel, - netievent_settlsctx, netievent_sockstop, /* for multilayer sockets */ } isc__netievent_type; @@ -1467,9 +1465,6 @@ isc__nm_streamdns_stoplistening(isc_nmsocket_t *sock); void isc__nm_streamdns_cleanup_data(isc_nmsocket_t *sock); -void -isc__nm_async_streamdnscancel(isc__networker_t *worker, isc__netievent_t *ev0); - void isc__nm_streamdns_cancelread(isc_nmhandle_t *handle); @@ -1634,8 +1629,6 @@ isc__nmsocket_stop(isc_nmsocket_t *listener); NETIEVENT_SOCKET_REQ_RESULT_TYPE(sendcb); -NETIEVENT_SOCKET_HANDLE_TYPE(streamdnscancel); - NETIEVENT_SOCKET_TLSCTX_TYPE(settlsctx); NETIEVENT_SOCKET_TYPE(sockstop); @@ -1643,8 +1636,6 @@ NETIEVENT_SOCKET_TYPE(sockstop); NETIEVENT_SOCKET_REQ_RESULT_DECL(sendcb); -NETIEVENT_SOCKET_HANDLE_DECL(streamdnscancel); - NETIEVENT_SOCKET_TLSCTX_DECL(settlsctx); NETIEVENT_SOCKET_DECL(sockstop); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index b77b83f09f..13a63bc7e5 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(streamdnscancel); - NETIEVENT_CASE(settlsctx); NETIEVENT_CASE(sockstop); default: @@ -467,8 +465,6 @@ isc__nm_put_netievent(isc__networker_t *worker, void *ievent) { isc__networker_unref(worker); } -NETIEVENT_SOCKET_HANDLE_DEF(streamdnscancel); - NETIEVENT_SOCKET_TLSCTX_DEF(settlsctx); NETIEVENT_SOCKET_DEF(sockstop); diff --git a/lib/isc/netmgr/streamdns.c b/lib/isc/netmgr/streamdns.c index 9fe73ea2c8..4e3cf5b5dc 100644 --- a/lib/isc/netmgr/streamdns.c +++ b/lib/isc/netmgr/streamdns.c @@ -962,6 +962,15 @@ isc__nm_streamdns_stoplistening(isc_nmsocket_t *sock) { isc__nmsocket_stop(sock); } +static void +streamdns_cancelread_cb(void *arg) { + isc_nmsocket_t *sock = arg; + REQUIRE(VALID_NMSOCK(sock)); + + streamdns_failed_read_cb(sock, ISC_R_EOF, false); + isc__nmsocket_detach(&sock); +} + void isc__nm_streamdns_cancelread(isc_nmhandle_t *handle) { isc_nmsocket_t *sock = NULL; @@ -972,24 +981,8 @@ isc__nm_streamdns_cancelread(isc_nmhandle_t *handle) { sock = handle->sock; - isc__netievent_streamdnscancel_t *ievent = - isc__nm_get_netievent_streamdnscancel(sock->worker, - handle->sock, handle); - isc__nm_enqueue_ievent(sock->worker, (isc__netievent_t *)ievent); -} - -void -isc__nm_async_streamdnscancel(isc__networker_t *worker, isc__netievent_t *ev0) { - isc__netievent_streamdnscancel_t *ievent = - (isc__netievent_streamdnscancel_t *)ev0; - isc_nmsocket_t *sock = ievent->sock; - - UNUSED(worker); - - REQUIRE(VALID_NMSOCK(sock)); - REQUIRE(sock->tid == isc_tid()); - - streamdns_failed_read_cb(sock, ISC_R_EOF, false); + isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL }); + isc_async_run(sock->worker->loop, streamdns_cancelread_cb, sock); } void