]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Convert reading from StreamDNS socket to to isc_async callback
authorOndřej Surý <ondrej@isc.org>
Thu, 23 Mar 2023 22:30:32 +0000 (23:30 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 24 Mar 2023 06:58:52 +0000 (07:58 +0100)
Simplify the reading from 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
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/streamdns.c

index 719b769f196ad68e5045a79663c58d3c34aa6e6b..3ab5e1158353549333283f9efdad380a427a048a 100644 (file)
@@ -250,7 +250,6 @@ struct isc_nmhandle {
 };
 
 typedef enum isc__netievent_type {
-       netievent_streamdnsread,
        netievent_streamdnscancel,
 
        netievent_settlsctx,
@@ -1451,9 +1450,6 @@ isc__nm_http_set_max_streams(isc_nmsocket_t *listener,
 
 #endif
 
-void
-isc__nm_async_streamdnsread(isc__networker_t *worker, isc__netievent_t *ev0);
-
 void
 isc__nm_streamdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb,
                       void *cbarg);
@@ -1638,7 +1634,6 @@ isc__nmsocket_stop(isc_nmsocket_t *listener);
 
 NETIEVENT_SOCKET_REQ_RESULT_TYPE(sendcb);
 
-NETIEVENT_SOCKET_TYPE(streamdnsread);
 NETIEVENT_SOCKET_HANDLE_TYPE(streamdnscancel);
 
 NETIEVENT_SOCKET_TLSCTX_TYPE(settlsctx);
@@ -1648,7 +1643,6 @@ NETIEVENT_SOCKET_TYPE(sockstop);
 
 NETIEVENT_SOCKET_REQ_RESULT_DECL(sendcb);
 
-NETIEVENT_SOCKET_DECL(streamdnsread);
 NETIEVENT_SOCKET_HANDLE_DECL(streamdnscancel);
 
 NETIEVENT_SOCKET_TLSCTX_DECL(settlsctx);
index 3c9f0458874798c0dcf9bfc768fcb9e86710007d..b77b83f09f1a038ce69bcbb408b17ccb086dab08 100644 (file)
@@ -439,7 +439,6 @@ process_netievent(void *arg) {
        isc__networker_t *worker = ievent->worker;
 
        switch (ievent->type) {
-               NETIEVENT_CASE(streamdnsread);
                NETIEVENT_CASE(streamdnscancel);
 
                NETIEVENT_CASE(settlsctx);
@@ -468,7 +467,6 @@ isc__nm_put_netievent(isc__networker_t *worker, void *ievent) {
        isc__networker_unref(worker);
 }
 
-NETIEVENT_SOCKET_DEF(streamdnsread);
 NETIEVENT_SOCKET_HANDLE_DEF(streamdnscancel);
 
 NETIEVENT_SOCKET_TLSCTX_DEF(settlsctx);
index 1905364ad053f5f069af984d8dff6a419bde4138..9fe73ea2c84d6266dd7c752971f958defd0c8c57 100644 (file)
@@ -14,6 +14,7 @@
 #include <limits.h>
 #include <unistd.h>
 
+#include <isc/async.h>
 #include <isc/atomic.h>
 #include <isc/result.h>
 #include <isc/thread.h>
@@ -797,26 +798,26 @@ isc__nm_streamdns_cleanup_data(isc_nmsocket_t *sock) {
        }
 }
 
-void
-isc__nm_async_streamdnsread(isc__networker_t *worker, isc__netievent_t *ev0) {
-       isc__netievent_streamdnsread_t *ievent =
-               (isc__netievent_streamdnsread_t *)ev0;
-       isc_nmsocket_t *sock = ievent->sock;
+static void
+streamdns_read_cb(void *arg) {
+       isc_nmsocket_t *sock = arg;
 
+       REQUIRE(VALID_NMSOCK(sock));
        REQUIRE(sock->tid == isc_tid());
-       UNUSED(worker);
 
        if (streamdns_closing(sock)) {
                streamdns_failed_read_cb(sock, ISC_R_CANCELED, false);
-               return;
+               goto detach;
        }
 
        if (sock->streamdns.reading) {
-               return;
+               goto detach;
        }
 
        INSIST(VALID_NMHANDLE(sock->outerhandle));
        streamdns_handle_incoming_data(sock, sock->outerhandle, NULL, 0);
+detach:
+       isc__nmsocket_detach(&sock);
 }
 
 void
@@ -847,9 +848,8 @@ isc__nm_streamdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb,
        if (!closing && isc_dnsstream_assembler_result(sock->streamdns.input) ==
                                ISC_R_UNSET)
        {
-               isc__netievent_streamdnsread_t event = { .sock = sock };
-               isc__nm_async_streamdnsread(sock->worker,
-                                           (isc__netievent_t *)&event);
+               isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL });
+               streamdns_read_cb(sock);
                return;
        }
 
@@ -863,9 +863,9 @@ isc__nm_streamdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb,
         * 2. Due to the above, we need to make the operation
         *    asynchronous to keep the socket state consistent.
         */
-       isc__netievent_streamdnsread_t *ievent =
-               isc__nm_get_netievent_streamdnsread(sock->worker, sock);
-       isc__nm_enqueue_ievent(sock->worker, (isc__netievent_t *)ievent);
+
+       isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL });
+       isc_async_run(sock->worker->loop, streamdns_read_cb, sock);
 }
 
 void