2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

use a linked list, rather than a counter, to keep track of sockets. This makes

debugging easier.  Also, while here, s/EMPTY/ISC_LIST_EMPTY/g
This commit is contained in:
Michael Graff
2000-06-02 01:27:27 +00:00
parent 1c70c5ee90
commit 0a161e9da7

View File

@@ -123,6 +123,7 @@ struct isc_socket {
isc_sockettype_t type; isc_sockettype_t type;
/* Locked by socket lock. */ /* Locked by socket lock. */
ISC_LINK(isc_socket_t) link;
unsigned int references; unsigned int references;
int fd; int fd;
isc_result_t recv_result; isc_result_t recv_result;
@@ -169,7 +170,7 @@ struct isc_socketmgr {
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t lock; isc_mutex_t lock;
/* Locked by manager lock. */ /* Locked by manager lock. */
unsigned int nsockets; /* sockets managed */ ISC_LIST(isc_socket_t) socklist;
isc_thread_t watcher; isc_thread_t watcher;
isc_condition_t shutdown_ok; isc_condition_t shutdown_ok;
fd_set read_fds; fd_set read_fds;
@@ -954,12 +955,10 @@ destroy(isc_socket_t **sockp) {
*/ */
manager->fds[sock->fd] = NULL; manager->fds[sock->fd] = NULL;
manager->fdstate[sock->fd] = CLOSE_PENDING; manager->fdstate[sock->fd] = CLOSE_PENDING;
select_poke(sock->manager, sock->fd); select_poke(manager, sock->fd);
manager->nsockets--; ISC_LIST_UNLINK(manager->socklist, sock, link);
manager_log(manager, CREATION,
"sockets %d", manager->nsockets);
if (manager->nsockets == 0) if (ISC_LIST_EMPTY(manager->socklist))
SIGNAL(&manager->shutdown_ok); SIGNAL(&manager->shutdown_ok);
/* /*
@@ -1007,6 +1006,8 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type,
sock->type = type; sock->type = type;
sock->fd = -1; sock->fd = -1;
ISC_LINK_INIT(sock, link);
/* /*
* set up list of readers and writers to be initially empty * set up list of readers and writers to be initially empty
*/ */
@@ -1080,9 +1081,9 @@ free_socket(isc_socket_t **socketp) {
INSIST(!sock->pending_recv); INSIST(!sock->pending_recv);
INSIST(!sock->pending_send); INSIST(!sock->pending_send);
INSIST(!sock->pending_accept); INSIST(!sock->pending_accept);
INSIST(EMPTY(sock->recv_list)); INSIST(ISC_LIST_EMPTY(sock->recv_list));
INSIST(EMPTY(sock->send_list)); INSIST(ISC_LIST_EMPTY(sock->send_list));
INSIST(EMPTY(sock->accept_list)); INSIST(ISC_LIST_EMPTY(sock->accept_list));
sock->magic = 0; sock->magic = 0;
@@ -1186,9 +1187,7 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
manager->fds[sock->fd] = sock; manager->fds[sock->fd] = sock;
manager->fdstate[sock->fd] = MANAGED; manager->fdstate[sock->fd] = MANAGED;
manager->nsockets++; ISC_LIST_APPEND(manager->socklist, sock, link);
manager_log(manager, CREATION,
"sockets %d", manager->nsockets);
if (manager->maxfd < sock->fd) if (manager->maxfd < sock->fd)
manager->maxfd = sock->fd; manager->maxfd = sock->fd;
@@ -1505,7 +1504,7 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
/* /*
* Poke watcher if there are more pending accepts. * Poke watcher if there are more pending accepts.
*/ */
if (!EMPTY(sock->accept_list)) if (!ISC_LIST_EMPTY(sock->accept_list))
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
@@ -1539,9 +1538,7 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
manager->fdstate[fd] = MANAGED; manager->fdstate[fd] = MANAGED;
if (manager->maxfd < fd) if (manager->maxfd < fd)
manager->maxfd = fd; manager->maxfd = fd;
manager->nsockets++; ISC_LIST_APPEND(manager->socklist, sock, link);
manager_log(manager, CREATION,
"sockets %d", manager->nsockets);
UNLOCK(&manager->lock); UNLOCK(&manager->lock);
socket_log(sock, &dev->newsocket->address, CREATION, socket_log(sock, &dev->newsocket->address, CREATION,
@@ -1637,7 +1634,7 @@ internal_recv(isc_task_t *me, isc_event_t *ev) {
} }
poke: poke:
if (!EMPTY(sock->recv_list)) if (!ISC_LIST_EMPTY(sock->recv_list))
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
@@ -1708,7 +1705,7 @@ internal_send(isc_task_t *me, isc_event_t *ev) {
} }
poke: poke:
if (!EMPTY(sock->send_list)) if (!ISC_LIST_EMPTY(sock->send_list))
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
@@ -1956,7 +1953,7 @@ isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) {
manager->magic = SOCKET_MANAGER_MAGIC; manager->magic = SOCKET_MANAGER_MAGIC;
manager->mctx = mctx; manager->mctx = mctx;
memset(manager->fds, 0, sizeof(manager->fds)); memset(manager->fds, 0, sizeof(manager->fds));
manager->nsockets = 0; ISC_LIST_INIT(manager->socklist);
if (isc_mutex_init(&manager->lock) != ISC_R_SUCCESS) { if (isc_mutex_init(&manager->lock) != ISC_R_SUCCESS) {
isc_mem_put(mctx, manager, sizeof *manager); isc_mem_put(mctx, manager, sizeof *manager);
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -2034,14 +2031,11 @@ isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
LOCK(&manager->lock); LOCK(&manager->lock);
manager_log(manager, CREATION,
"sockets %d", manager->nsockets);
/* /*
* Wait for all sockets to be destroyed. * Wait for all sockets to be destroyed.
*/ */
while (manager->nsockets != 0) { while (!ISC_LIST_EMPTY(manager->socklist)) {
manager_log(manager, CREATION, manager_log(manager, CREATION, "sockets exist");
"sockets %d", manager->nsockets);
WAIT(&manager->shutdown_ok, &manager->lock); WAIT(&manager->shutdown_ok, &manager->lock);
} }
@@ -2653,7 +2647,7 @@ isc_socket_accept(isc_socket_t *sock,
* is no race condition. We will keep the lock for such a short * is no race condition. We will keep the lock for such a short
* bit of time waking it up now or later won't matter all that much. * bit of time waking it up now or later won't matter all that much.
*/ */
if (EMPTY(sock->accept_list)) if (ISC_LIST_EMPTY(sock->accept_list))
select_poke(manager, sock->fd); select_poke(manager, sock->fd);
ISC_LIST_ENQUEUE(sock->accept_list, dev, ev_link); ISC_LIST_ENQUEUE(sock->accept_list, dev, ev_link);
@@ -2951,7 +2945,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
* o Reset any state needed. * o Reset any state needed.
*/ */
if (((how & ISC_SOCKCANCEL_RECV) == ISC_SOCKCANCEL_RECV) if (((how & ISC_SOCKCANCEL_RECV) == ISC_SOCKCANCEL_RECV)
&& !EMPTY(sock->recv_list)) { && !ISC_LIST_EMPTY(sock->recv_list)) {
isc_socketevent_t *dev; isc_socketevent_t *dev;
isc_socketevent_t *next; isc_socketevent_t *next;
isc_task_t *current_task; isc_task_t *current_task;
@@ -2970,7 +2964,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
} }
if (((how & ISC_SOCKCANCEL_SEND) == ISC_SOCKCANCEL_SEND) if (((how & ISC_SOCKCANCEL_SEND) == ISC_SOCKCANCEL_SEND)
&& !EMPTY(sock->send_list)) { && !ISC_LIST_EMPTY(sock->send_list)) {
isc_socketevent_t *dev; isc_socketevent_t *dev;
isc_socketevent_t *next; isc_socketevent_t *next;
isc_task_t *current_task; isc_task_t *current_task;
@@ -2989,7 +2983,7 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
} }
if (((how & ISC_SOCKCANCEL_ACCEPT) == ISC_SOCKCANCEL_ACCEPT) if (((how & ISC_SOCKCANCEL_ACCEPT) == ISC_SOCKCANCEL_ACCEPT)
&& !EMPTY(sock->accept_list)) { && !ISC_LIST_EMPTY(sock->accept_list)) {
isc_socket_newconnev_t *dev; isc_socket_newconnev_t *dev;
isc_socket_newconnev_t *next; isc_socket_newconnev_t *next;
isc_task_t *current_task; isc_task_t *current_task;
@@ -3083,7 +3077,7 @@ isc_socket_recvmark(isc_socket_t *sock,
* If the queue is empty, simply return the last error we got on * If the queue is empty, simply return the last error we got on
* this socket as the result code, and send off the done event. * this socket as the result code, and send off the done event.
*/ */
if (EMPTY(sock->recv_list)) { if (ISC_LIST_EMPTY(sock->recv_list)) {
send_recvdone_event(sock, &dev, sock->recv_result); send_recvdone_event(sock, &dev, sock->recv_result);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
@@ -3140,7 +3134,7 @@ isc_socket_sendmark(isc_socket_t *sock,
* If the queue is empty, simply return the last error we got on * If the queue is empty, simply return the last error we got on
* this socket as the result code, and send off the done event. * this socket as the result code, and send off the done event.
*/ */
if (EMPTY(sock->send_list)) { if (ISC_LIST_EMPTY(sock->send_list)) {
send_senddone_event(sock, &dev, sock->send_result); send_senddone_event(sock, &dev, sock->send_result);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);