mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
checkpoint
This commit is contained in:
parent
dd5f72cc1c
commit
f497ab709d
@ -57,10 +57,22 @@ client_recv(isc_task_t *task, isc_event_t *ev)
|
||||
isc_event_free(&ev);
|
||||
dev = NULL;
|
||||
|
||||
/*
|
||||
* Go idle.
|
||||
*/
|
||||
ISC_LIST_UNLINK(cm->running, client, link);
|
||||
ISC_LIST_APPEND(cm->idle, client, link);
|
||||
|
||||
clientmgr_can_die(cm);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXXMLG Nothing to do right now, just go idle.
|
||||
*/
|
||||
ISC_LIST_UNLINK(cm->running, client, link);
|
||||
ISC_LIST_APPEND(cm->idle, client, link);
|
||||
|
||||
client_start_recv(cm);
|
||||
|
||||
isc_event_free(&ev);
|
||||
@ -101,6 +113,13 @@ client_start_recv(clientmgr_t *cm)
|
||||
*/
|
||||
cm->flags |= CLIENTMGR_FLAG_RECVPENDING;
|
||||
|
||||
/*
|
||||
* Remove the client from the idle list, and put it on the running
|
||||
* list.
|
||||
*/
|
||||
ISC_LIST_UNLINK(cm->idle, client, link);
|
||||
ISC_LIST_APPEND(cm->running, client, link);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,20 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <lwres/lwres.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/assertions.h>
|
||||
#include <isc/event.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <lwres/lwres.h>
|
||||
|
||||
#include "client.h"
|
||||
|
||||
/*
|
||||
@ -46,6 +52,10 @@ main(int argc, char **argv)
|
||||
{
|
||||
isc_mem_t *mem;
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_socketmgr_t *sockmgr;
|
||||
isc_socket_t *sock;
|
||||
isc_sockaddr_t localhost;
|
||||
struct in_addr lh_addr;
|
||||
isc_result_t result;
|
||||
unsigned int i, j;
|
||||
client_t *client;
|
||||
@ -53,22 +63,56 @@ main(int argc, char **argv)
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
|
||||
isc_app_start();
|
||||
|
||||
mem = NULL;
|
||||
result = isc_mem_create(0, 0, &mem);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
|
||||
cmgr = isc_mem_get(mem, sizeof(clientmgr_t) * NTHREADS);
|
||||
cmgr = isc_mem_get(mem, sizeof(clientmgr_t) * NTASKS);
|
||||
INSIST(cmgr != NULL);
|
||||
|
||||
/*
|
||||
* Create a task manager.
|
||||
*/
|
||||
taskmgr = NULL;
|
||||
result = isc_taskmgr_create(mem, NTHREADS, 0, &taskmgr);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Create a socket manager.
|
||||
*/
|
||||
sockmgr = NULL;
|
||||
result = isc_socketmgr_create(mem, &sockmgr);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* We'll need a socket. It will be a UDP socket, and bound to
|
||||
* 127.0.0.1 port LWRES_UDP_PORT.
|
||||
*/
|
||||
sock = NULL;
|
||||
result = isc_socket_create(sockmgr, AF_INET, isc_sockettype_udp,
|
||||
&sock);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
|
||||
lh_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
isc_sockaddr_fromin(&localhost, &lh_addr, LWRES_UDP_PORT);
|
||||
|
||||
result = isc_socket_bind(sock, &localhost);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Create one task for each client manager.
|
||||
*/
|
||||
for (i = 0 ; i < NTASKS ; i++) {
|
||||
cmgr[i].task = NULL;
|
||||
cmgr[i].sock = sock;
|
||||
cmgr[i].flags = 0;
|
||||
ISC_EVENT_INIT(&cmgr[i].sdev, sizeof(isc_event_t),
|
||||
ISC_EVENTATTR_NOPURGE,
|
||||
0, LWRD_SHUTDOWN,
|
||||
client_shutdown, &cmgr[i], main,
|
||||
NULL, NULL);
|
||||
ISC_LIST_INIT(cmgr[i].idle);
|
||||
ISC_LIST_INIT(cmgr[i].running);
|
||||
result = isc_task_create(taskmgr, mem, 0, &cmgr[i].task);
|
||||
@ -88,7 +132,7 @@ main(int argc, char **argv)
|
||||
if (client == NULL)
|
||||
break;
|
||||
for (j = 0 ; j < ntasks ; j++) {
|
||||
client[j].socket = NULL;
|
||||
client[j].clientmgr = &cmgr[j];
|
||||
ISC_LINK_INIT(&client[j], link);
|
||||
ISC_LIST_APPEND(cmgr[j].idle, &client[j], link);
|
||||
}
|
||||
@ -96,13 +140,71 @@ main(int argc, char **argv)
|
||||
INSIST(i > 0);
|
||||
|
||||
/*
|
||||
* Now, create a socket. Issue one read request for each task
|
||||
* we have.
|
||||
* Issue one read request for each task we have.
|
||||
*/
|
||||
for (j = 0 ; j < ntasks ; j++) {
|
||||
result = client_start_recv(&cmgr[j]);
|
||||
INSIST(result == ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for ^c or kill.
|
||||
*/
|
||||
isc_mem_stats(mem, stdout);
|
||||
isc_app_run();
|
||||
isc_mem_stats(mem, stdout);
|
||||
|
||||
/*
|
||||
* Send a shutdown event to every task.
|
||||
*/
|
||||
for (j = 0 ; j < ntasks ; j++) {
|
||||
isc_event_t *ev;
|
||||
|
||||
ev = &cmgr[j].sdev;
|
||||
isc_task_send(cmgr[j].task, &ev);
|
||||
printf("Sending shutdown events to task %p\n", cmgr[j].task);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for the tasks to all die.
|
||||
*/
|
||||
printf("Waiting for task manager to die...\n");
|
||||
isc_taskmgr_destroy(&taskmgr);
|
||||
|
||||
/*
|
||||
* Wait for everything to die off by waiting for the sockets
|
||||
* to be detached.
|
||||
*/
|
||||
printf("Waiting for socket manager to die...\n");
|
||||
isc_socket_detach(&sock);
|
||||
isc_socketmgr_destroy(&sockmgr);
|
||||
|
||||
/*
|
||||
* Free up memory allocated. This is somewhat magical. We allocated
|
||||
* the client_t's in blocks, but the first task always has the
|
||||
* first pointer. Just loop here, freeing them.
|
||||
*/
|
||||
client = ISC_LIST_HEAD(cmgr[0].idle);
|
||||
while (client != NULL) {
|
||||
ISC_LIST_UNLINK(cmgr[0].idle, client, link);
|
||||
isc_mem_put(mem, client, sizeof(client_t) * ntasks);
|
||||
client = ISC_LIST_HEAD(cmgr[0].idle);
|
||||
}
|
||||
INSIST(ISC_LIST_EMPTY(cmgr[0].running));
|
||||
|
||||
/*
|
||||
* Now, kill off the client manager structures.
|
||||
*/
|
||||
isc_mem_put(mem, cmgr, sizeof(clientmgr_t) * NTASKS);
|
||||
cmgr = NULL;
|
||||
|
||||
/*
|
||||
* Kill the memory system.
|
||||
*/
|
||||
isc_mem_stats(mem, stdout);
|
||||
isc_mem_destroy(&mem);
|
||||
|
||||
isc_app_finish();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user