2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 22:45:39 +00:00

Allocate events in the client structure, and use isc_socket_sendto2()

and isc_socket_recv2() for sending and receiving packets.  In the send
case, pass the IMMEDIATE flag to avoid receiving an event on send completion
if possible.
This commit is contained in:
Brian Wellington
2001-02-12 21:45:37 +00:00
parent 1f7f8d5c07
commit 2d1db4e2c0
2 changed files with 41 additions and 13 deletions

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: client.c,v 1.147 2001/02/12 20:26:11 bwelling Exp $ */ /* $Id: client.c,v 1.148 2001/02/12 21:45:36 bwelling Exp $ */
#include <config.h> #include <config.h>
@@ -233,6 +233,8 @@ client_free(ns_client_t *client) {
ns_query_free(client); ns_query_free(client);
isc_mem_put(client->mctx, client->sendbuf, SEND_BUFFER_SIZE); isc_mem_put(client->mctx, client->sendbuf, SEND_BUFFER_SIZE);
isc_mem_put(client->mctx, client->recvbuf, RECV_BUFFER_SIZE); isc_mem_put(client->mctx, client->recvbuf, RECV_BUFFER_SIZE);
isc_event_free((isc_event_t **)&client->sendevent);
isc_event_free((isc_event_t **)&client->recvevent);
isc_timer_detach(&client->timer); isc_timer_detach(&client->timer);
if (client->tcpbuf != NULL) if (client->tcpbuf != NULL)
@@ -626,6 +628,7 @@ client_senddone(isc_task_t *task, isc_event_t *event) {
client = sevent->ev_arg; client = sevent->ev_arg;
REQUIRE(NS_CLIENT_VALID(client)); REQUIRE(NS_CLIENT_VALID(client));
REQUIRE(task == client->task); REQUIRE(task == client->task);
REQUIRE(sevent == client->sendevent);
UNUSED(task); UNUSED(task);
@@ -646,8 +649,6 @@ client_senddone(isc_task_t *task, isc_event_t *event) {
client->tcpbuf = NULL; client->tcpbuf = NULL;
} }
isc_event_free(&event);
if (exit_check(client)) if (exit_check(client))
return; return;
@@ -738,10 +739,14 @@ client_sendpkg(ns_client_t *client, isc_buffer_t *buffer) {
CTRACE("sendto"); CTRACE("sendto");
result = isc_socket_sendto(socket, &r, client->task, client_senddone, result = isc_socket_sendto2(socket, &r, client->task,
client, address, pktinfo); address, pktinfo,
if (result == ISC_R_SUCCESS) { client->sendevent, ISC_SOCKFLAG_IMMEDIATE);
if (result == ISC_R_SUCCESS || result == ISC_R_INPROGRESS) {
client->nsends++; client->nsends++;
if (result == ISC_R_SUCCESS)
client_senddone(client->task,
(isc_event_t *)client->sendevent);
} }
return (result); return (result);
} }
@@ -1156,6 +1161,7 @@ client_request(isc_task_t *task, isc_event_t *event) {
if (event->ev_type == ISC_SOCKEVENT_RECVDONE) { if (event->ev_type == ISC_SOCKEVENT_RECVDONE) {
INSIST(!TCP_CLIENT(client)); INSIST(!TCP_CLIENT(client));
sevent = (isc_socketevent_t *)event; sevent = (isc_socketevent_t *)event;
REQUIRE(sevent == client->recvevent);
isc_buffer_init(&tbuffer, sevent->region.base, sevent->n); isc_buffer_init(&tbuffer, sevent->region.base, sevent->n);
isc_buffer_add(&tbuffer, sevent->n); isc_buffer_add(&tbuffer, sevent->n);
buffer = &tbuffer; buffer = &tbuffer;
@@ -1459,8 +1465,6 @@ client_request(isc_task_t *task, isc_event_t *event) {
cleanup_serverlock: cleanup_serverlock:
dns_zonemgr_unlockconf(ns_g_server->zonemgr, isc_rwlocktype_read); dns_zonemgr_unlockconf(ns_g_server->zonemgr, isc_rwlocktype_read);
RWUNLOCK(&ns_g_server->conflock, isc_rwlocktype_read); RWUNLOCK(&ns_g_server->conflock, isc_rwlocktype_read);
isc_event_free(&event);
} }
static void static void
@@ -1540,9 +1544,25 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp)
if (client->sendbuf == NULL) if (client->sendbuf == NULL)
goto cleanup_message; goto cleanup_message;
client->sendevent = (isc_socketevent_t *)
isc_event_allocate(manager->mctx, client,
ISC_SOCKEVENT_SENDDONE,
client_senddone, client,
sizeof(isc_socketevent_t));
if (client->sendevent == NULL)
goto cleanup_sendbuf;
client->recvbuf = isc_mem_get(manager->mctx, RECV_BUFFER_SIZE); client->recvbuf = isc_mem_get(manager->mctx, RECV_BUFFER_SIZE);
if (client->recvbuf == NULL) if (client->recvbuf == NULL)
goto cleanup_sendbuf; goto cleanup_sendevent;
client->recvevent = (isc_socketevent_t *)
isc_event_allocate(manager->mctx, client,
ISC_SOCKEVENT_RECVDONE,
client_request, client,
sizeof(isc_socketevent_t));
if (client->recvevent == NULL)
goto cleanup_recvbuf;
client->magic = NS_CLIENT_MAGIC; client->magic = NS_CLIENT_MAGIC;
client->mctx = manager->mctx; client->mctx = manager->mctx;
@@ -1592,7 +1612,7 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp)
*/ */
result = ns_query_init(client); result = ns_query_init(client);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup_recvbuf; goto cleanup_recvevent;
CTRACE("create"); CTRACE("create");
@@ -1600,9 +1620,15 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp)
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
cleanup_recvevent:
isc_event_free((isc_event_t **)&client->recvevent);
cleanup_recvbuf: cleanup_recvbuf:
isc_mem_put(manager->mctx, client->recvbuf, RECV_BUFFER_SIZE); isc_mem_put(manager->mctx, client->recvbuf, RECV_BUFFER_SIZE);
cleanup_sendevent:
isc_event_free((isc_event_t **)&client->sendevent);
cleanup_sendbuf: cleanup_sendbuf:
isc_mem_put(manager->mctx, client->sendbuf, SEND_BUFFER_SIZE); isc_mem_put(manager->mctx, client->sendbuf, SEND_BUFFER_SIZE);
@@ -1792,8 +1818,8 @@ client_udprecv(ns_client_t *client) {
r.base = client->recvbuf; r.base = client->recvbuf;
r.length = RECV_BUFFER_SIZE; r.length = RECV_BUFFER_SIZE;
result = isc_socket_recv(client->udpsocket, &r, 1, result = isc_socket_recv2(client->udpsocket, &r, 1,
client->task, client_request, client); client->task, client->recvevent, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_socket_recv() failed: %s", "isc_socket_recv() failed: %s",

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: client.h,v 1.51 2001/01/29 19:49:51 bwelling Exp $ */ /* $Id: client.h,v 1.52 2001/02/12 21:45:37 bwelling Exp $ */
#ifndef NAMED_CLIENT_H #ifndef NAMED_CLIENT_H
#define NAMED_CLIENT_H 1 #define NAMED_CLIENT_H 1
@@ -110,6 +110,8 @@ struct ns_client {
isc_boolean_t timerset; isc_boolean_t timerset;
dns_message_t * message; dns_message_t * message;
unsigned char * sendbuf; unsigned char * sendbuf;
isc_socketevent_t * sendevent;
isc_socketevent_t * recvevent;
unsigned char * recvbuf; unsigned char * recvbuf;
dns_rdataset_t * opt; dns_rdataset_t * opt;
isc_uint16_t udpsize; isc_uint16_t udpsize;