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.
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
* 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);
/*%<
}
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);
}
void
-isc_nmsocket_detach(isc_nmsocket_t **sockp) {
+isc__nmsocket_detach(isc_nmsocket_t **sockp) {
REQUIRE(sockp != NULL && *sockp != NULL);
REQUIRE(VALID_NMSOCK(*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) {
* 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);
/*
* 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 *
*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);
isc_nmhandle_unref(handle);
}
- isc_nmsocket_detach(&sock);
+ isc__nmsocket_detach(&sock);
}
isc_result_t
UNUSED(worker);
ievent->sock->closehandle_cb(ievent->sock);
- isc_nmsocket_detach(&ievent->sock);
+ isc__nmsocket_detach(&ievent->sock);
}
static void
return (ISC_R_SUCCESS);
} else {
isc_result_t result = nsock->result;
- isc_nmsocket_detach(&nsock);
+ isc__nmsocket_detach(&nsock);
return (result);
}
}
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:
/*
* Detach the socket properly to make sure uv_close() is called.
*/
- isc_nmsocket_detach(&csock);
+ isc__nmsocket_detach(&csock);
}
void
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);
}
sock->pquota = NULL;
UNLOCK(&sock->lock);
- isc_nmsocket_detach(&sock);
+ isc__nmsocket_detach(&sock);
}
static void
/*
* The socket was attached just before we called isc_quota_attach_cb().
*/
- isc_nmsocket_detach(&ievent->sock);
+ isc__nmsocket_detach(&ievent->sock);
}
/*
* 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, "a,
&ssock->quotacb);
if (result == ISC_R_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]);
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((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);
}
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
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();
return (ISC_R_SUCCESS);
} else {
atomic_store(&dnslistensock->closed, true);
- isc_nmsocket_detach(&dnslistensock);
+ isc__nmsocket_detach(&dnslistensock);
return (result);
}
}
if (sock->outer != NULL) {
isc_nm_stoplistening(sock->outer);
- isc_nmsocket_detach(&sock->outer);
+ isc__nmsocket_detach(&sock->outer);
}
}
*/
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);
}
#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) {
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
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
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);