aboutsummaryrefslogtreecommitdiff
path: root/contrib/bind9/lib/dns/dispatch.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind9/lib/dns/dispatch.c')
-rw-r--r--contrib/bind9/lib/dns/dispatch.c83
1 files changed, 44 insertions, 39 deletions
diff --git a/contrib/bind9/lib/dns/dispatch.c b/contrib/bind9/lib/dns/dispatch.c
index 91ef2c5ee0aa..02accdf4c193 100644
--- a/contrib/bind9/lib/dns/dispatch.c
+++ b/contrib/bind9/lib/dns/dispatch.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2006 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
@@ -15,7 +15,9 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: dispatch.c,v 1.101.2.6.2.13 2006/07/19 00:44:04 marka Exp $ */
+/* $Id: dispatch.c,v 1.116.18.13 2007/02/07 23:57:58 marka Exp $ */
+
+/*! \file */
#include <config.h>
@@ -43,12 +45,12 @@ typedef ISC_LIST(dns_dispentry_t) dns_displist_t;
typedef struct dns_qid {
unsigned int magic;
- unsigned int qid_nbuckets; /* hash table size */
- unsigned int qid_increment; /* id increment on collision */
+ unsigned int qid_nbuckets; /*%< hash table size */
+ unsigned int qid_increment; /*%< id increment on collision */
isc_mutex_t lock;
- isc_lfsr_t qid_lfsr1; /* state generator info */
- isc_lfsr_t qid_lfsr2; /* state generator info */
- dns_displist_t *qid_table; /* the table itself */
+ isc_lfsr_t qid_lfsr1; /*%< state generator info */
+ isc_lfsr_t qid_lfsr2; /*%< state generator info */
+ dns_displist_t *qid_table; /*%< the table itself */
} dns_qid_t;
struct dns_dispatchmgr {
@@ -66,18 +68,18 @@ struct dns_dispatchmgr {
/* locked by buffer lock */
dns_qid_t *qid;
isc_mutex_t buffer_lock;
- unsigned int buffers; /* allocated buffers */
- unsigned int buffersize; /* size of each buffer */
- unsigned int maxbuffers; /* max buffers */
+ unsigned int buffers; /*%< allocated buffers */
+ unsigned int buffersize; /*%< size of each buffer */
+ unsigned int maxbuffers; /*%< max buffers */
/* Locked internally. */
isc_mutex_t pool_lock;
- isc_mempool_t *epool; /* memory pool for events */
- isc_mempool_t *rpool; /* memory pool for replies */
- isc_mempool_t *dpool; /* dispatch allocations */
- isc_mempool_t *bpool; /* memory pool for buffers */
+ isc_mempool_t *epool; /*%< memory pool for events */
+ isc_mempool_t *rpool; /*%< memory pool for replies */
+ isc_mempool_t *dpool; /*%< dispatch allocations */
+ isc_mempool_t *bpool; /*%< memory pool for buffers */
- isc_entropy_t *entropy; /* entropy source */
+ isc_entropy_t *entropy; /*%< entropy source */
};
#define MGR_SHUTTINGDOWN 0x00000001U
@@ -103,32 +105,32 @@ struct dns_dispentry {
struct dns_dispatch {
/* Unlocked. */
- unsigned int magic; /* magic */
- dns_dispatchmgr_t *mgr; /* dispatch manager */
- isc_task_t *task; /* internal task */
- isc_socket_t *socket; /* isc socket attached to */
- isc_sockaddr_t local; /* local address */
- unsigned int maxrequests; /* max requests */
+ unsigned int magic; /*%< magic */
+ dns_dispatchmgr_t *mgr; /*%< dispatch manager */
+ isc_task_t *task; /*%< internal task */
+ isc_socket_t *socket; /*%< isc socket attached to */
+ isc_sockaddr_t local; /*%< local address */
+ unsigned int maxrequests; /*%< max requests */
isc_event_t *ctlevent;
- /* Locked by mgr->lock. */
+ /*% Locked by mgr->lock. */
ISC_LINK(dns_dispatch_t) link;
/* Locked by "lock". */
- isc_mutex_t lock; /* locks all below */
+ isc_mutex_t lock; /*%< locks all below */
isc_sockettype_t socktype;
unsigned int attributes;
- unsigned int refcount; /* number of users */
- dns_dispatchevent_t *failsafe_ev; /* failsafe cancel event */
+ unsigned int refcount; /*%< number of users */
+ dns_dispatchevent_t *failsafe_ev; /*%< failsafe cancel event */
unsigned int shutting_down : 1,
shutdown_out : 1,
connected : 1,
tcpmsg_valid : 1,
- recv_pending : 1; /* is a recv() pending? */
+ recv_pending : 1; /*%< is a recv() pending? */
isc_result_t shutdown_why;
- unsigned int requests; /* how many requests we have */
- unsigned int tcpbuffers; /* allocated buffers */
- dns_tcpmsg_t tcpmsg; /* for tcp streams */
+ unsigned int requests; /*%< how many requests we have */
+ unsigned int tcpbuffers; /*%< allocated buffers */
+ dns_tcpmsg_t tcpmsg; /*%< for tcp streams */
dns_qid_t *qid;
};
@@ -970,6 +972,9 @@ startrecv(dns_dispatch_t *disp) {
INSIST(disp->recv_pending == 0);
disp->recv_pending = 1;
break;
+ default:
+ INSIST(0);
+ break;
}
}
@@ -1239,6 +1244,7 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr,
if (isc_mempool_create(mgr->mctx, buffersize,
&mgr->bpool) != ISC_R_SUCCESS) {
+ UNLOCK(&mgr->buffer_lock);
return (ISC_R_NOMEMORY);
}
@@ -1396,6 +1402,7 @@ qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets,
{
dns_qid_t *qid;
unsigned int i;
+ isc_result_t result;
REQUIRE(VALID_DISPATCHMGR(mgr));
REQUIRE(buckets < 2097169); /* next prime > 65536 * 32 */
@@ -1413,12 +1420,12 @@ qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets,
return (ISC_R_NOMEMORY);
}
- if (isc_mutex_init(&qid->lock) != ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_mutex_init failed");
+ result = isc_mutex_init(&qid->lock);
+ if (result != ISC_R_SUCCESS) {
isc_mem_put(mgr->mctx, qid->qid_table,
buckets * sizeof(dns_displist_t));
isc_mem_put(mgr->mctx, qid, sizeof(*qid));
- return (ISC_R_UNEXPECTED);
+ return (result);
}
for (i = 0; i < buckets; i++)
@@ -1471,7 +1478,7 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
dns_dispatch_t **dispp)
{
dns_dispatch_t *disp;
- isc_result_t res;
+ isc_result_t result;
REQUIRE(VALID_DISPATCHMGR(mgr));
REQUIRE(dispp != NULL && *dispp == NULL);
@@ -1502,15 +1509,13 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
disp->tcpbuffers = 0;
disp->qid = NULL;
- if (isc_mutex_init(&disp->lock) != ISC_R_SUCCESS) {
- res = ISC_R_UNEXPECTED;
- UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_mutex_init failed");
+ result = isc_mutex_init(&disp->lock);
+ if (result != ISC_R_SUCCESS)
goto deallocate;
- }
disp->failsafe_ev = allocate_event(disp);
if (disp->failsafe_ev == NULL) {
- res = ISC_R_NOMEMORY;
+ result = ISC_R_NOMEMORY;
goto kill_lock;
}
@@ -1527,7 +1532,7 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
deallocate:
isc_mempool_put(mgr->dpool, disp);
- return (res);
+ return (result);
}