]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
make isc_nmsocket_{attach,detach}{} functions private
authorEvan Hunt <each@isc.org>
Thu, 4 Jun 2020 21:54:36 +0000 (14:54 -0700)
committerWitold Kręcicki <wpk@isc.org>
Thu, 18 Jun 2020 08:03:39 +0000 (10:03 +0200)
there is no need for a caller to reference-count socket objects.
they need tto be able tto close listener sockets (i.e., those
returned by isc_nm_listen{udp,tcp,tcpdns}), and an isc_nmsocket_close()
function has been added for that. other sockets are only accessed via
handles.

lib/isc/include/isc/netmgr.h
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/udp.c
lib/isc/win32/libisc.def.in
lib/ns/interfacemgr.c

index 0c3f3adc7fb936ae39357a55fbbbc783d60f85b6..52262d585786a4f2177f0bb972eceac0cdc15a9e 100644 (file)
@@ -57,26 +57,13 @@ isc_nm_closedown(isc_nm_t *mgr);
 int
 isc_nm_tid(void);
 
-/*
- * isc_nm_freehandle frees a handle, releasing resources
- */
-void
-isc_nm_freehandle(isc_nmhandle_t *handle);
-
-void
-isc_nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target);
-/*%<
- * isc_nmsocket_attach attaches to a socket, increasing refcount
- */
-
-void
-isc_nmsocket_close(isc_nmsocket_t *sock);
-
 void
-isc_nmsocket_detach(isc_nmsocket_t **socketp);
+isc_nmsocket_close(isc_nmsocket_t **sockp);
 /*%<
- * isc_nmsocket_detach detaches from socket, decreasing refcount
- * and possibly destroying the socket if it's no longer referenced.
+ * isc_nmsocket_close() detaches a listening socket that was
+ * created by isc_nm_listenudp(), isc_nm_listentcp(), or
+ * isc_nm_listentcpdns(). Once there are no remaining child
+ * sockets with active handles, the socket will be closed.
  */
 
 void
index b15e6fac2908f10f05da9ebb51fc2d62537f4565..981f4aa635fe797d84344679c12425b82aa49333 100644 (file)
@@ -615,6 +615,19 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
  * and its interface to 'iface'.
  */
 
+void
+isc__nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target);
+/*%<
+ * Attach to a socket, increasing refcount
+ */
+
+void
+isc__nmsocket_detach(isc_nmsocket_t **socketp);
+/*%<
+ * Detach from socket, decreasing refcount and possibly destroying the
+ * socket if it's no longer referenced.
+ */
+
 void
 isc__nmsocket_prep_destroy(isc_nmsocket_t *sock);
 /*%<
index 35469b6dff1ddd77e397905f0f2e3274755e8838..dd589788924944e49826ddb40daf83a671b5bb47 100644 (file)
@@ -686,7 +686,7 @@ isc__nmsocket_active(isc_nmsocket_t *sock) {
 }
 
 void
-isc_nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target) {
+isc__nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target) {
        REQUIRE(VALID_NMSOCK(sock));
        REQUIRE(target != NULL && *target == NULL);
 
@@ -878,7 +878,7 @@ isc__nmsocket_prep_destroy(isc_nmsocket_t *sock) {
 }
 
 void
-isc_nmsocket_detach(isc_nmsocket_t **sockp) {
+isc__nmsocket_detach(isc_nmsocket_t **sockp) {
        REQUIRE(sockp != NULL && *sockp != NULL);
        REQUIRE(VALID_NMSOCK(*sockp));
 
@@ -901,6 +901,17 @@ isc_nmsocket_detach(isc_nmsocket_t **sockp) {
        }
 }
 
+void
+isc_nmsocket_close(isc_nmsocket_t **sockp) {
+       REQUIRE(sockp != NULL);
+       REQUIRE(VALID_NMSOCK(*sockp));
+       REQUIRE((*sockp)->type == isc_nm_udplistener ||
+               (*sockp)->type == isc_nm_tcplistener ||
+               (*sockp)->type == isc_nm_tcpdnslistener);
+
+       isc__nmsocket_detach(sockp);
+}
+
 void
 isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
                   isc_nmiface_t *iface) {
@@ -1171,7 +1182,7 @@ isc_nmhandle_unref(isc_nmhandle_t *handle) {
         * be deleted by another thread while we're deactivating the
         * handle.
         */
-       isc_nmsocket_attach(sock, &tmp);
+       isc__nmsocket_attach(sock, &tmp);
        nmhandle_deactivate(sock, handle);
 
        /*
@@ -1189,13 +1200,13 @@ isc_nmhandle_unref(isc_nmhandle_t *handle) {
                         * The socket will be finally detached by the closecb
                         * event handler.
                         */
-                       isc_nmsocket_attach(sock, &event->sock);
+                       isc__nmsocket_attach(sock, &event->sock);
                        isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
                                               (isc__netievent_t *)event);
                }
        }
 
-       isc_nmsocket_detach(&tmp);
+       isc__nmsocket_detach(&tmp);
 }
 
 void *
@@ -1262,7 +1273,7 @@ isc__nm_uvreq_get(isc_nm_t *mgr, isc_nmsocket_t *sock) {
 
        *req = (isc__nm_uvreq_t){ .magic = 0 };
        req->uv_req.req.data = req;
-       isc_nmsocket_attach(sock, &req->sock);
+       isc__nmsocket_attach(sock, &req->sock);
        req->magic = UVREQ_MAGIC;
 
        return (req);
@@ -1299,7 +1310,7 @@ isc__nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock) {
                isc_nmhandle_unref(handle);
        }
 
-       isc_nmsocket_detach(&sock);
+       isc__nmsocket_detach(&sock);
 }
 
 isc_result_t
@@ -1388,7 +1399,7 @@ isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0) {
        UNUSED(worker);
 
        ievent->sock->closehandle_cb(ievent->sock);
-       isc_nmsocket_detach(&ievent->sock);
+       isc__nmsocket_detach(&ievent->sock);
 }
 
 static void
index 9710f8464f2b51e7553d34a94f9617a02c4bce9c..5a6ac45735c30f0cd12ee83146f6ca1af709c6e7 100644 (file)
@@ -209,7 +209,7 @@ isc_nm_listentcp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_cb_t cb,
                return (ISC_R_SUCCESS);
        } else {
                isc_result_t result = nsock->result;
-               isc_nmsocket_detach(&nsock);
+               isc__nmsocket_detach(&nsock);
                return (result);
        }
 }
@@ -379,14 +379,14 @@ isc__nm_async_tcpchildaccept(isc__networker_t *worker, isc__netievent_t *ev0) {
                goto error;
        }
 
-       isc_nmsocket_attach(ssock, &csock->server);
+       isc__nmsocket_attach(ssock, &csock->server);
 
        handle = isc__nmhandle_get(csock, NULL, &local);
 
        INSIST(ssock->rcb.accept != NULL);
        csock->read_timeout = ssock->mgr->init;
        ssock->rcb.accept(handle, ISC_R_SUCCESS, ssock->rcbarg);
-       isc_nmsocket_detach(&csock);
+       isc__nmsocket_detach(&csock);
        return;
 
 error:
@@ -405,7 +405,7 @@ error:
        /*
         * Detach the socket properly to make sure uv_close() is called.
         */
-       isc_nmsocket_detach(&csock);
+       isc__nmsocket_detach(&csock);
 }
 
 void
@@ -416,7 +416,7 @@ isc__nm_tcp_stoplistening(isc_nmsocket_t *sock) {
        REQUIRE(!isc__nm_in_netthread());
 
        ievent = isc__nm_get_ievent(sock->mgr, netievent_tcpstop);
-       isc_nmsocket_attach(sock, &ievent->sock);
+       isc__nmsocket_attach(sock, &ievent->sock);
        isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
                               (isc__netievent_t *)ievent);
 }
@@ -462,7 +462,7 @@ tcp_listenclose_cb(uv_handle_t *handle) {
        sock->pquota = NULL;
        UNLOCK(&sock->lock);
 
-       isc_nmsocket_detach(&sock);
+       isc__nmsocket_detach(&sock);
 }
 
 static void
@@ -697,7 +697,7 @@ isc__nm_async_tcpaccept(isc__networker_t *worker, isc__netievent_t *ev0) {
        /*
         * The socket was attached just before we called isc_quota_attach_cb().
         */
-       isc_nmsocket_detach(&ievent->sock);
+       isc__nmsocket_detach(&ievent->sock);
 }
 
 /*
@@ -741,7 +741,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
                 * we need to - but we risk a race then.)
                 */
                isc_nmsocket_t *tsock = NULL;
-               isc_nmsocket_attach(ssock, &tsock);
+               isc__nmsocket_attach(ssock, &tsock);
                result = isc_quota_attach_cb(ssock->pquota, &quota,
                                             &ssock->quotacb);
                if (result == ISC_R_QUOTA) {
@@ -754,7 +754,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
                 * We're under quota, so there's no need to wait;
                 * Detach the socket.
                 */
-               isc_nmsocket_detach(&tsock);
+               isc__nmsocket_detach(&tsock);
        }
 
        isc__nm_incstats(ssock->mgr, ssock->statsindex[STATID_ACCEPT]);
@@ -915,7 +915,7 @@ timer_close_cb(uv_handle_t *uvhandle) {
 
        REQUIRE(VALID_NMSOCK(sock));
 
-       isc_nmsocket_detach(&sock->server);
+       isc__nmsocket_detach(&sock->server);
        uv_close(&sock->uv_handle.handle, tcp_close_cb);
 }
 
@@ -933,7 +933,7 @@ tcp_close_direct(isc_nmsocket_t *sock) {
                uv_close((uv_handle_t *)&sock->timer, timer_close_cb);
        } else {
                if (sock->server != NULL) {
-                       isc_nmsocket_detach(&sock->server);
+                       isc__nmsocket_detach(&sock->server);
                }
                uv_close(&sock->uv_handle.handle, tcp_close_cb);
        }
index 7e3d1728dd2f30e54eb4548b3d55e0a6f9f0bacc..0f7819fc231c7ec0887767d9177771f138d4d4e3 100644 (file)
@@ -82,7 +82,7 @@ static void
 timer_close_cb(uv_handle_t *handle) {
        isc_nmsocket_t *sock = (isc_nmsocket_t *)uv_handle_get_data(handle);
        INSIST(VALID_NMSOCK(sock));
-       isc_nmsocket_detach(&sock);
+       isc__nmsocket_detach(&sock);
 }
 
 static void
@@ -122,8 +122,8 @@ dnslisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
                           handle->sock->iface);
 
        dnssock->extrahandlesize = dnslistensock->extrahandlesize;
-       isc_nmsocket_attach(dnslistensock, &dnssock->listener);
-       isc_nmsocket_attach(handle->sock, &dnssock->outer);
+       isc__nmsocket_attach(dnslistensock, &dnssock->listener);
+       isc__nmsocket_attach(handle->sock, &dnssock->outer);
        dnssock->peer = handle->sock->peer;
        dnssock->read_timeout = handle->sock->mgr->init;
        dnssock->tid = isc_nm_tid();
@@ -310,7 +310,7 @@ isc_nm_listentcpdns(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
                return (ISC_R_SUCCESS);
        } else {
                atomic_store(&dnslistensock->closed, true);
-               isc_nmsocket_detach(&dnslistensock);
+               isc__nmsocket_detach(&dnslistensock);
                return (result);
        }
 }
@@ -327,7 +327,7 @@ isc__nm_tcpdns_stoplistening(isc_nmsocket_t *sock) {
 
        if (sock->outer != NULL) {
                isc_nm_stoplistening(sock->outer);
-               isc_nmsocket_detach(&sock->outer);
+               isc__nmsocket_detach(&sock->outer);
        }
 }
 
@@ -517,10 +517,10 @@ tcpdns_close_direct(isc_nmsocket_t *sock) {
                 */
                if (sock->outer != NULL) {
                        sock->outer->rcb.recv = NULL;
-                       isc_nmsocket_detach(&sock->outer);
+                       isc__nmsocket_detach(&sock->outer);
                }
                if (sock->listener != NULL) {
-                       isc_nmsocket_detach(&sock->listener);
+                       isc__nmsocket_detach(&sock->listener);
                }
                atomic_store(&sock->closed, true);
        }
index 066e5edcb57126b72e01b7e56a1be560118464cc..bd40fa38119261b66b2638f34ffb3825cf387326 100644 (file)
@@ -152,7 +152,8 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
 #endif
        uv_udp_init_ex(&worker->loop, &sock->uv_handle.udp, uv_init_flags);
        uv_handle_set_data(&sock->uv_handle.handle, NULL);
-       isc_nmsocket_attach(sock, (isc_nmsocket_t **)&sock->uv_handle.udp.data);
+       isc__nmsocket_attach(sock,
+                            (isc_nmsocket_t **)&sock->uv_handle.udp.data);
 
        r = uv_udp_open(&sock->uv_handle.udp, sock->fd);
        if (r == 0) {
@@ -186,7 +187,7 @@ udp_close_cb(uv_handle_t *handle) {
        isc_nmsocket_t *sock = uv_handle_get_data(handle);
        atomic_store(&sock->closed, true);
 
-       isc_nmsocket_detach((isc_nmsocket_t **)&sock->uv_handle.udp.data);
+       isc__nmsocket_detach((isc_nmsocket_t **)&sock->uv_handle.udp.data);
 }
 
 static void
index 681b730731bf53bf56e543c1a1d89014239e1b47..4a7ec68056ed48be5797a5fbd81fd1f867aa3723 100644 (file)
@@ -464,7 +464,7 @@ isc_nm_tcp_settimeouts
 isc_nm_tcpdns_keepalive
 isc_nm_tcpdns_sequential
 isc_nm_tid
-isc_nmsocket_detach
+isc_nmsocket_close
 isc__nm_acquire_interlocked
 isc__nm_drop_interlocked
 isc__nm_acquire_interlocked_force
index 633485f6478ee9b5503d06b011198bdaa206dac0..30ecbcda29ff9e4ecd5753c6b2ff8f670c7330d0 100644 (file)
@@ -553,11 +553,11 @@ void
 ns_interface_shutdown(ns_interface_t *ifp) {
        if (ifp->udplistensocket != NULL) {
                isc_nm_stoplistening(ifp->udplistensocket);
-               isc_nmsocket_detach(&ifp->udplistensocket);
+               isc_nmsocket_close(&ifp->udplistensocket);
        }
        if (ifp->tcplistensocket != NULL) {
                isc_nm_stoplistening(ifp->tcplistensocket);
-               isc_nmsocket_detach(&ifp->tcplistensocket);
+               isc_nmsocket_close(&ifp->tcplistensocket);
        }
        if (ifp->clientmgr != NULL) {
                ns_clientmgr_destroy(&ifp->clientmgr);