diff --git a/bin/named/client.c b/bin/named/client.c index 3494781edc..366a866eed 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -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; diff --git a/bin/named/include/named/client.h b/bin/named/include/named/client.h index 28103da00a..9f5e325188 100644 --- a/bin/named/include/named/client.h +++ b/bin/named/include/named/client.h @@ -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 diff --git a/bin/named/query.c b/bin/named/query.c index c12a07d9f3..a6f921b74c 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -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); } diff --git a/bin/named/xfrout.c b/bin/named/xfrout.c index 9b13141623..1f3344f9c8 100644 --- a/bin/named/xfrout.c +++ b/bin/named/xfrout.c @@ -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 @@ -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));