]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Convert canceling UDP socket to to isc_async callback
authorOndřej Surý <ondrej@isc.org>
Thu, 23 Mar 2023 21:16:47 +0000 (22:16 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 24 Mar 2023 06:58:52 +0000 (07:58 +0100)
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
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/udp.c

index 345f477295c8310b27a23efcae100fe6e4ab709c..c7f18eb0ff120e8423245aa01d35db9aec106194 100644 (file)
@@ -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);
index ba4a712b01ad7ca7ee80697ee45aa40bf8e74e2b..6059c7850b38476480b3db14e7dfa81c32d2dc40 100644 (file)
@@ -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);
index a443a1df40f6e06deb58969035265b4bcf0e4695..0ab10c525302704dc38655319bebd1e6bcce6d9a 100644 (file)
@@ -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);
+       REQUIRE(sock->tid == isc_tid());
+       REQUIRE(atomic_load(&sock->client));
 
-       isc__nm_enqueue_ievent(sock->worker, (isc__netievent_t *)ievent);
+       isc__nm_failed_read_cb(sock, ISC_R_EOF, false);
+       isc__nmsocket_detach(&sock);
 }
 
 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));
+isc__nm_udp_cancelread(isc_nmhandle_t *handle) {
+       REQUIRE(VALID_NMHANDLE(handle));
 
-       sock = ievent->sock;
+       isc_nmsocket_t *sock = handle->sock;
 
-       REQUIRE(sock->tid == isc_tid());
-       REQUIRE(atomic_load(&sock->client));
+       REQUIRE(VALID_NMSOCK(sock));
+       REQUIRE(sock->type == isc_nm_udpsocket);
 
-       isc__nm_failed_read_cb(sock, ISC_R_EOF, false);
+       isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL });
+       isc_async_run(sock->worker->loop, udp_cancelread_cb, sock);
 }