mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Make client reference counts work the same way as all
other reference counts: replace ns_client_wait() and ns_client_unwait() by ns_client_attach() and ns_client_detach(), respectively
This commit is contained in:
@@ -273,8 +273,8 @@ exit_check(ns_client_t *client) {
|
||||
*
|
||||
* - The resolver will not shut down until the view refcount is zero
|
||||
* - The view refcount does not go to zero until all clients detach
|
||||
* - The client does not detach from the view until nwaiting is zero
|
||||
* - nwaiting does not go to zero until the resolver has shut down
|
||||
* - The client does not detach from the view until references is zero
|
||||
* - references does not go to zero until the resolver has shut down
|
||||
*
|
||||
*/
|
||||
if (client->newstate == NS_CLIENTSTATE_FREED && client->view != NULL)
|
||||
@@ -295,7 +295,7 @@ exit_check(ns_client_t *client) {
|
||||
isc_socket_cancel(socket, client->task,
|
||||
ISC_SOCKCANCEL_SEND);
|
||||
}
|
||||
if (! (client->nsends == 0 && client->nwaiting == 0)) {
|
||||
if (! (client->nsends == 0 && client->references == 0)) {
|
||||
/*
|
||||
* Still waiting for I/O cancel completion.
|
||||
* or lingering references.
|
||||
@@ -1045,7 +1045,7 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp)
|
||||
client->naccepts = 0;
|
||||
client->nreads = 0;
|
||||
client->nsends = 0;
|
||||
client->nwaiting = 0;
|
||||
client->references = 0;
|
||||
client->attributes = 0;
|
||||
client->view = NULL;
|
||||
client->lockview = NULL;
|
||||
@@ -1236,8 +1236,20 @@ client_accept(ns_client_t *client) {
|
||||
}
|
||||
|
||||
void
|
||||
ns_client_wait(ns_client_t *client) {
|
||||
client->nwaiting++;
|
||||
ns_client_attach(ns_client_t *source, ns_client_t **targetp) {
|
||||
REQUIRE(NS_CLIENT_VALID(source));
|
||||
REQUIRE(targetp != NULL && *targetp == NULL);
|
||||
source->references++;
|
||||
*targetp = source;
|
||||
}
|
||||
|
||||
void
|
||||
ns_client_detach(ns_client_t **clientp) {
|
||||
ns_client_t *client = *clientp;
|
||||
client->references--;
|
||||
INSIST(client->references >= 0);
|
||||
*clientp = NULL;
|
||||
(void) exit_check(client);
|
||||
}
|
||||
|
||||
isc_boolean_t
|
||||
@@ -1245,13 +1257,6 @@ ns_client_shuttingdown(ns_client_t *client) {
|
||||
return (client->newstate == NS_CLIENTSTATE_FREED);
|
||||
}
|
||||
|
||||
void
|
||||
ns_client_unwait(ns_client_t *client) {
|
||||
client->nwaiting--;
|
||||
INSIST(client->nwaiting >= 0);
|
||||
(void) exit_check(client);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
ns_client_replace(ns_client_t *client) {
|
||||
isc_result_t result;
|
||||
|
@@ -88,7 +88,7 @@ struct ns_client {
|
||||
int naccepts;
|
||||
int nreads;
|
||||
int nsends;
|
||||
int nwaiting;
|
||||
int references;
|
||||
unsigned int attributes;
|
||||
isc_task_t * task;
|
||||
dns_view_t * view;
|
||||
@@ -167,16 +167,15 @@ ns_client_shuttingdown(ns_client_t *client);
|
||||
*/
|
||||
|
||||
void
|
||||
ns_client_wait(ns_client_t *client);
|
||||
ns_client_attach(ns_client_t *source, ns_client_t **target);
|
||||
/*
|
||||
* Increment reference count. The client object will
|
||||
* not be destroyed while the reference count is nonzero.
|
||||
* Attach '*targetp' to 'source'.
|
||||
*/
|
||||
|
||||
void
|
||||
ns_client_unwait(ns_client_t *client);
|
||||
ns_client_detach(ns_client_t **clientp);
|
||||
/*
|
||||
* Decrement reference count.
|
||||
* Detach '*clientp' from its client.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
|
@@ -1679,7 +1679,7 @@ query_resume(isc_task_t *task, isc_event_t *event) {
|
||||
isc_event_free(&event);
|
||||
ns_client_next(client, ISC_R_CANCELED);
|
||||
/* This may destroy the client. */
|
||||
ns_client_unwait(client);
|
||||
ns_client_detach(&client);
|
||||
} else {
|
||||
RWLOCK(&ns_g_server->conflock, isc_rwlocktype_read);
|
||||
dns_zonemgr_lockconf(ns_g_server->zonemgr, isc_rwlocktype_read);
|
||||
@@ -2597,7 +2597,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
|
||||
|
||||
if (eresult != ISC_R_SUCCESS && !PARTIALANSWER(client)) {
|
||||
ns_client_error(client, eresult);
|
||||
ns_client_unwait(client);
|
||||
ns_client_detach(&client);
|
||||
} else if (!RECURSING(client)) {
|
||||
/*
|
||||
* We are done. Make a final tweak to the AA bit if the
|
||||
@@ -2609,7 +2609,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
|
||||
client->message->flags |= DNS_MESSAGEFLAG_AA;
|
||||
|
||||
ns_client_send(client);
|
||||
ns_client_unwait(client);
|
||||
ns_client_detach(&client);
|
||||
}
|
||||
CTRACE("query_find: done");
|
||||
}
|
||||
@@ -2672,7 +2672,8 @@ ns_query_start(ns_client_t *client) {
|
||||
dns_message_t *message = client->message;
|
||||
dns_rdataset_t *rdataset;
|
||||
isc_boolean_t set_ra = ISC_TRUE;
|
||||
|
||||
ns_client_t *qclient;
|
||||
|
||||
CTRACE("ns_query_start");
|
||||
|
||||
/*
|
||||
@@ -2802,6 +2803,7 @@ ns_query_start(ns_client_t *client) {
|
||||
*/
|
||||
message->flags |= DNS_MESSAGEFLAG_AD;
|
||||
|
||||
ns_client_wait(client);
|
||||
query_find(client, NULL);
|
||||
qclient = NULL;
|
||||
ns_client_attach(client, &qclient);
|
||||
query_find(qclient, NULL);
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: xfrout.c,v 1.42 2000/02/09 22:58:45 gson Exp $ */
|
||||
/* $Id: xfrout.c,v 1.43 2000/02/11 20:56:18 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -1052,8 +1052,8 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id,
|
||||
if (xfr == NULL)
|
||||
return (DNS_R_NOMEMORY);
|
||||
xfr->mctx = mctx;
|
||||
xfr->client = client;
|
||||
ns_client_wait(client);
|
||||
xfr->client = NULL;
|
||||
ns_client_attach(client, &xfr->client);
|
||||
xfr->id = id;
|
||||
xfr->qname = qname;
|
||||
xfr->qtype = qtype;
|
||||
@@ -1397,7 +1397,7 @@ xfrout_ctx_destroy(xfrout_ctx_t **xfrp) {
|
||||
if (xfr->db != NULL)
|
||||
dns_db_detach(&xfr->db);
|
||||
|
||||
ns_client_unwait(xfr->client);
|
||||
ns_client_detach(&xfr->client);
|
||||
|
||||
isc_mem_put(xfr->mctx, xfr, sizeof(*xfr));
|
||||
|
||||
|
Reference in New Issue
Block a user