mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
make isc_nmsocket_{attach,detach}{} functions private
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.
This commit is contained in:
committed by
Witold Kręcicki
parent
be032d64ff
commit
9e740cad21
@@ -57,26 +57,13 @@ isc_nm_closedown(isc_nm_t *mgr);
|
|||||||
int
|
int
|
||||||
isc_nm_tid(void);
|
isc_nm_tid(void);
|
||||||
|
|
||||||
/*
|
|
||||||
* isc_nm_freehandle frees a handle, releasing resources
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
isc_nm_freehandle(isc_nmhandle_t *handle);
|
isc_nmsocket_close(isc_nmsocket_t **sockp);
|
||||||
|
|
||||||
void
|
|
||||||
isc_nmsocket_attach(isc_nmsocket_t *sock, isc_nmsocket_t **target);
|
|
||||||
/*%<
|
/*%<
|
||||||
* isc_nmsocket_attach attaches to a socket, increasing refcount
|
* 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
|
||||||
void
|
* sockets with active handles, the socket will be closed.
|
||||||
isc_nmsocket_close(isc_nmsocket_t *sock);
|
|
||||||
|
|
||||||
void
|
|
||||||
isc_nmsocket_detach(isc_nmsocket_t **socketp);
|
|
||||||
/*%<
|
|
||||||
* isc_nmsocket_detach detaches from socket, decreasing refcount
|
|
||||||
* and possibly destroying the socket if it's no longer referenced.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -615,6 +615,19 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
|
|||||||
* and its interface to 'iface'.
|
* 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
|
void
|
||||||
isc__nmsocket_prep_destroy(isc_nmsocket_t *sock);
|
isc__nmsocket_prep_destroy(isc_nmsocket_t *sock);
|
||||||
/*%<
|
/*%<
|
||||||
|
@@ -686,7 +686,7 @@ isc__nmsocket_active(isc_nmsocket_t *sock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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(VALID_NMSOCK(sock));
|
||||||
REQUIRE(target != NULL && *target == NULL);
|
REQUIRE(target != NULL && *target == NULL);
|
||||||
|
|
||||||
@@ -878,7 +878,7 @@ isc__nmsocket_prep_destroy(isc_nmsocket_t *sock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_nmsocket_detach(isc_nmsocket_t **sockp) {
|
isc__nmsocket_detach(isc_nmsocket_t **sockp) {
|
||||||
REQUIRE(sockp != NULL && *sockp != NULL);
|
REQUIRE(sockp != NULL && *sockp != NULL);
|
||||||
REQUIRE(VALID_NMSOCK(*sockp));
|
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
|
void
|
||||||
isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
|
isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
|
||||||
isc_nmiface_t *iface) {
|
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
|
* be deleted by another thread while we're deactivating the
|
||||||
* handle.
|
* handle.
|
||||||
*/
|
*/
|
||||||
isc_nmsocket_attach(sock, &tmp);
|
isc__nmsocket_attach(sock, &tmp);
|
||||||
nmhandle_deactivate(sock, handle);
|
nmhandle_deactivate(sock, handle);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1189,13 +1200,13 @@ isc_nmhandle_unref(isc_nmhandle_t *handle) {
|
|||||||
* The socket will be finally detached by the closecb
|
* The socket will be finally detached by the closecb
|
||||||
* event handler.
|
* event handler.
|
||||||
*/
|
*/
|
||||||
isc_nmsocket_attach(sock, &event->sock);
|
isc__nmsocket_attach(sock, &event->sock);
|
||||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||||
(isc__netievent_t *)event);
|
(isc__netievent_t *)event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_nmsocket_detach(&tmp);
|
isc__nmsocket_detach(&tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
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 = (isc__nm_uvreq_t){ .magic = 0 };
|
||||||
req->uv_req.req.data = req;
|
req->uv_req.req.data = req;
|
||||||
isc_nmsocket_attach(sock, &req->sock);
|
isc__nmsocket_attach(sock, &req->sock);
|
||||||
req->magic = UVREQ_MAGIC;
|
req->magic = UVREQ_MAGIC;
|
||||||
|
|
||||||
return (req);
|
return (req);
|
||||||
@@ -1299,7 +1310,7 @@ isc__nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock) {
|
|||||||
isc_nmhandle_unref(handle);
|
isc_nmhandle_unref(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_nmsocket_detach(&sock);
|
isc__nmsocket_detach(&sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
@@ -1388,7 +1399,7 @@ isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0) {
|
|||||||
UNUSED(worker);
|
UNUSED(worker);
|
||||||
|
|
||||||
ievent->sock->closehandle_cb(ievent->sock);
|
ievent->sock->closehandle_cb(ievent->sock);
|
||||||
isc_nmsocket_detach(&ievent->sock);
|
isc__nmsocket_detach(&ievent->sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -209,7 +209,7 @@ isc_nm_listentcp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_cb_t cb,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
isc_result_t result = nsock->result;
|
isc_result_t result = nsock->result;
|
||||||
isc_nmsocket_detach(&nsock);
|
isc__nmsocket_detach(&nsock);
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,14 +379,14 @@ isc__nm_async_tcpchildaccept(isc__networker_t *worker, isc__netievent_t *ev0) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_nmsocket_attach(ssock, &csock->server);
|
isc__nmsocket_attach(ssock, &csock->server);
|
||||||
|
|
||||||
handle = isc__nmhandle_get(csock, NULL, &local);
|
handle = isc__nmhandle_get(csock, NULL, &local);
|
||||||
|
|
||||||
INSIST(ssock->rcb.accept != NULL);
|
INSIST(ssock->rcb.accept != NULL);
|
||||||
csock->read_timeout = ssock->mgr->init;
|
csock->read_timeout = ssock->mgr->init;
|
||||||
ssock->rcb.accept(handle, ISC_R_SUCCESS, ssock->rcbarg);
|
ssock->rcb.accept(handle, ISC_R_SUCCESS, ssock->rcbarg);
|
||||||
isc_nmsocket_detach(&csock);
|
isc__nmsocket_detach(&csock);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@@ -405,7 +405,7 @@ error:
|
|||||||
/*
|
/*
|
||||||
* Detach the socket properly to make sure uv_close() is called.
|
* Detach the socket properly to make sure uv_close() is called.
|
||||||
*/
|
*/
|
||||||
isc_nmsocket_detach(&csock);
|
isc__nmsocket_detach(&csock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -416,7 +416,7 @@ isc__nm_tcp_stoplistening(isc_nmsocket_t *sock) {
|
|||||||
REQUIRE(!isc__nm_in_netthread());
|
REQUIRE(!isc__nm_in_netthread());
|
||||||
|
|
||||||
ievent = isc__nm_get_ievent(sock->mgr, netievent_tcpstop);
|
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__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||||
(isc__netievent_t *)ievent);
|
(isc__netievent_t *)ievent);
|
||||||
}
|
}
|
||||||
@@ -462,7 +462,7 @@ tcp_listenclose_cb(uv_handle_t *handle) {
|
|||||||
sock->pquota = NULL;
|
sock->pquota = NULL;
|
||||||
UNLOCK(&sock->lock);
|
UNLOCK(&sock->lock);
|
||||||
|
|
||||||
isc_nmsocket_detach(&sock);
|
isc__nmsocket_detach(&sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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().
|
* 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.)
|
* we need to - but we risk a race then.)
|
||||||
*/
|
*/
|
||||||
isc_nmsocket_t *tsock = NULL;
|
isc_nmsocket_t *tsock = NULL;
|
||||||
isc_nmsocket_attach(ssock, &tsock);
|
isc__nmsocket_attach(ssock, &tsock);
|
||||||
result = isc_quota_attach_cb(ssock->pquota, "a,
|
result = isc_quota_attach_cb(ssock->pquota, "a,
|
||||||
&ssock->quotacb);
|
&ssock->quotacb);
|
||||||
if (result == ISC_R_QUOTA) {
|
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;
|
* We're under quota, so there's no need to wait;
|
||||||
* Detach the socket.
|
* Detach the socket.
|
||||||
*/
|
*/
|
||||||
isc_nmsocket_detach(&tsock);
|
isc__nmsocket_detach(&tsock);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc__nm_incstats(ssock->mgr, ssock->statsindex[STATID_ACCEPT]);
|
isc__nm_incstats(ssock->mgr, ssock->statsindex[STATID_ACCEPT]);
|
||||||
@@ -915,7 +915,7 @@ timer_close_cb(uv_handle_t *uvhandle) {
|
|||||||
|
|
||||||
REQUIRE(VALID_NMSOCK(sock));
|
REQUIRE(VALID_NMSOCK(sock));
|
||||||
|
|
||||||
isc_nmsocket_detach(&sock->server);
|
isc__nmsocket_detach(&sock->server);
|
||||||
uv_close(&sock->uv_handle.handle, tcp_close_cb);
|
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);
|
uv_close((uv_handle_t *)&sock->timer, timer_close_cb);
|
||||||
} else {
|
} else {
|
||||||
if (sock->server != NULL) {
|
if (sock->server != NULL) {
|
||||||
isc_nmsocket_detach(&sock->server);
|
isc__nmsocket_detach(&sock->server);
|
||||||
}
|
}
|
||||||
uv_close(&sock->uv_handle.handle, tcp_close_cb);
|
uv_close(&sock->uv_handle.handle, tcp_close_cb);
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,7 @@ static void
|
|||||||
timer_close_cb(uv_handle_t *handle) {
|
timer_close_cb(uv_handle_t *handle) {
|
||||||
isc_nmsocket_t *sock = (isc_nmsocket_t *)uv_handle_get_data(handle);
|
isc_nmsocket_t *sock = (isc_nmsocket_t *)uv_handle_get_data(handle);
|
||||||
INSIST(VALID_NMSOCK(sock));
|
INSIST(VALID_NMSOCK(sock));
|
||||||
isc_nmsocket_detach(&sock);
|
isc__nmsocket_detach(&sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -122,8 +122,8 @@ dnslisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
|
|||||||
handle->sock->iface);
|
handle->sock->iface);
|
||||||
|
|
||||||
dnssock->extrahandlesize = dnslistensock->extrahandlesize;
|
dnssock->extrahandlesize = dnslistensock->extrahandlesize;
|
||||||
isc_nmsocket_attach(dnslistensock, &dnssock->listener);
|
isc__nmsocket_attach(dnslistensock, &dnssock->listener);
|
||||||
isc_nmsocket_attach(handle->sock, &dnssock->outer);
|
isc__nmsocket_attach(handle->sock, &dnssock->outer);
|
||||||
dnssock->peer = handle->sock->peer;
|
dnssock->peer = handle->sock->peer;
|
||||||
dnssock->read_timeout = handle->sock->mgr->init;
|
dnssock->read_timeout = handle->sock->mgr->init;
|
||||||
dnssock->tid = isc_nm_tid();
|
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);
|
return (ISC_R_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
atomic_store(&dnslistensock->closed, true);
|
atomic_store(&dnslistensock->closed, true);
|
||||||
isc_nmsocket_detach(&dnslistensock);
|
isc__nmsocket_detach(&dnslistensock);
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ isc__nm_tcpdns_stoplistening(isc_nmsocket_t *sock) {
|
|||||||
|
|
||||||
if (sock->outer != NULL) {
|
if (sock->outer != NULL) {
|
||||||
isc_nm_stoplistening(sock->outer);
|
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) {
|
if (sock->outer != NULL) {
|
||||||
sock->outer->rcb.recv = NULL;
|
sock->outer->rcb.recv = NULL;
|
||||||
isc_nmsocket_detach(&sock->outer);
|
isc__nmsocket_detach(&sock->outer);
|
||||||
}
|
}
|
||||||
if (sock->listener != NULL) {
|
if (sock->listener != NULL) {
|
||||||
isc_nmsocket_detach(&sock->listener);
|
isc__nmsocket_detach(&sock->listener);
|
||||||
}
|
}
|
||||||
atomic_store(&sock->closed, true);
|
atomic_store(&sock->closed, true);
|
||||||
}
|
}
|
||||||
|
@@ -152,7 +152,8 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
|
|||||||
#endif
|
#endif
|
||||||
uv_udp_init_ex(&worker->loop, &sock->uv_handle.udp, uv_init_flags);
|
uv_udp_init_ex(&worker->loop, &sock->uv_handle.udp, uv_init_flags);
|
||||||
uv_handle_set_data(&sock->uv_handle.handle, NULL);
|
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);
|
r = uv_udp_open(&sock->uv_handle.udp, sock->fd);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
@@ -186,7 +187,7 @@ udp_close_cb(uv_handle_t *handle) {
|
|||||||
isc_nmsocket_t *sock = uv_handle_get_data(handle);
|
isc_nmsocket_t *sock = uv_handle_get_data(handle);
|
||||||
atomic_store(&sock->closed, true);
|
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
|
static void
|
||||||
|
@@ -464,7 +464,7 @@ isc_nm_tcp_settimeouts
|
|||||||
isc_nm_tcpdns_keepalive
|
isc_nm_tcpdns_keepalive
|
||||||
isc_nm_tcpdns_sequential
|
isc_nm_tcpdns_sequential
|
||||||
isc_nm_tid
|
isc_nm_tid
|
||||||
isc_nmsocket_detach
|
isc_nmsocket_close
|
||||||
isc__nm_acquire_interlocked
|
isc__nm_acquire_interlocked
|
||||||
isc__nm_drop_interlocked
|
isc__nm_drop_interlocked
|
||||||
isc__nm_acquire_interlocked_force
|
isc__nm_acquire_interlocked_force
|
||||||
|
@@ -553,11 +553,11 @@ void
|
|||||||
ns_interface_shutdown(ns_interface_t *ifp) {
|
ns_interface_shutdown(ns_interface_t *ifp) {
|
||||||
if (ifp->udplistensocket != NULL) {
|
if (ifp->udplistensocket != NULL) {
|
||||||
isc_nm_stoplistening(ifp->udplistensocket);
|
isc_nm_stoplistening(ifp->udplistensocket);
|
||||||
isc_nmsocket_detach(&ifp->udplistensocket);
|
isc_nmsocket_close(&ifp->udplistensocket);
|
||||||
}
|
}
|
||||||
if (ifp->tcplistensocket != NULL) {
|
if (ifp->tcplistensocket != NULL) {
|
||||||
isc_nm_stoplistening(ifp->tcplistensocket);
|
isc_nm_stoplistening(ifp->tcplistensocket);
|
||||||
isc_nmsocket_detach(&ifp->tcplistensocket);
|
isc_nmsocket_close(&ifp->tcplistensocket);
|
||||||
}
|
}
|
||||||
if (ifp->clientmgr != NULL) {
|
if (ifp->clientmgr != NULL) {
|
||||||
ns_clientmgr_destroy(&ifp->clientmgr);
|
ns_clientmgr_destroy(&ifp->clientmgr);
|
||||||
|
Reference in New Issue
Block a user