2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 06:55:30 +00:00

conforming changes for task API revision

This commit is contained in:
Bob Halley
1998-12-16 02:05:38 +00:00
parent 835e240716
commit 0ab04d76c8
4 changed files with 55 additions and 94 deletions

View File

@@ -40,10 +40,10 @@
isc_memctx_t *mctx = NULL; isc_memctx_t *mctx = NULL;
int sockets_active = 0; int sockets_active = 0;
static isc_boolean_t my_send(isc_task_t *task, isc_event_t *event); static void my_send(isc_task_t *task, isc_event_t *event);
static isc_boolean_t my_recv(isc_task_t *task, isc_event_t *event); static void my_recv(isc_task_t *task, isc_event_t *event);
static isc_boolean_t static void
my_callback(isc_task_t *task, isc_event_t *event) my_callback(isc_task_t *task, isc_event_t *event)
{ {
char *name = event->arg; char *name = event->arg;
@@ -51,11 +51,9 @@ my_callback(isc_task_t *task, isc_event_t *event)
printf("task %s (%p)\n", name, task); printf("task %s (%p)\n", name, task);
fflush(stdout); fflush(stdout);
isc_event_free(&event); isc_event_free(&event);
return (ISC_FALSE);
} }
static isc_boolean_t static void
my_shutdown(isc_task_t *task, isc_event_t *event) my_shutdown(isc_task_t *task, isc_event_t *event)
{ {
char *name = event->arg; char *name = event->arg;
@@ -63,11 +61,9 @@ my_shutdown(isc_task_t *task, isc_event_t *event)
printf("shutdown %s (%p)\n", name, task); printf("shutdown %s (%p)\n", name, task);
fflush(stdout); fflush(stdout);
isc_event_free(&event); isc_event_free(&event);
return (ISC_TRUE);
} }
static isc_boolean_t static void
my_recv(isc_task_t *task, isc_event_t *event) my_recv(isc_task_t *task, isc_event_t *event)
{ {
isc_socket_t *sock; isc_socket_t *sock;
@@ -93,9 +89,8 @@ my_recv(isc_task_t *task, isc_event_t *event)
sockets_active--; sockets_active--;
if (sockets_active == 0) if (sockets_active == 0)
return (1); isc_task_shutdown(task);
return;
return (0);
} }
/* /*
@@ -120,11 +115,9 @@ my_recv(isc_task_t *task, isc_event_t *event)
isc_event_free(&event); isc_event_free(&event);
return (0);
} }
static isc_boolean_t static void
my_send(isc_task_t *task, isc_event_t *event) my_send(isc_task_t *task, isc_event_t *event)
{ {
isc_socket_t *sock; isc_socket_t *sock;
@@ -141,11 +134,9 @@ my_send(isc_task_t *task, isc_event_t *event)
isc_mem_put(event->mctx, dev->region.base, dev->region.length); isc_mem_put(event->mctx, dev->region.base, dev->region.length);
isc_event_free(&event); isc_event_free(&event);
return (0);
} }
static isc_boolean_t static void
my_http_get(isc_task_t *task, isc_event_t *event) my_http_get(isc_task_t *task, isc_event_t *event)
{ {
isc_socket_t *sock; isc_socket_t *sock;
@@ -163,11 +154,9 @@ my_http_get(isc_task_t *task, isc_event_t *event)
event->arg); event->arg);
isc_event_free(&event); isc_event_free(&event);
return (0);
} }
static isc_boolean_t static void
my_connect(isc_task_t *task, isc_event_t *event) my_connect(isc_task_t *task, isc_event_t *event)
{ {
isc_socket_t *sock; isc_socket_t *sock;
@@ -184,8 +173,7 @@ my_connect(isc_task_t *task, isc_event_t *event)
if (dev->result != ISC_R_SUCCESS) { if (dev->result != ISC_R_SUCCESS) {
isc_socket_detach(&sock); isc_socket_detach(&sock);
isc_event_free(&event); isc_event_free(&event);
return;
return (0);
} }
/* /*
@@ -200,18 +188,15 @@ my_connect(isc_task_t *task, isc_event_t *event)
isc_socket_send(sock, &region, task, my_http_get, event->arg); isc_socket_send(sock, &region, task, my_http_get, event->arg);
isc_event_free(&event); isc_event_free(&event);
return (0);
} }
static isc_boolean_t static void
my_listen(isc_task_t *task, isc_event_t *event) my_listen(isc_task_t *task, isc_event_t *event)
{ {
char *name = event->arg; char *name = event->arg;
isc_socket_newconnev_t *dev; isc_socket_newconnev_t *dev;
isc_region_t region; isc_region_t region;
isc_socket_t *oldsock; isc_socket_t *oldsock;
int ret;
dev = (isc_socket_newconnev_t *)event; dev = (isc_socket_newconnev_t *)event;
@@ -219,8 +204,6 @@ my_listen(isc_task_t *task, isc_event_t *event)
name, task, event->sender, dev->newsocket, dev->result); name, task, event->sender, dev->newsocket, dev->result);
fflush(stdout); fflush(stdout);
ret = 0;
if (dev->result == ISC_R_SUCCESS) { if (dev->result == ISC_R_SUCCESS) {
/* /*
* queue another listen on this socket * queue another listen on this socket
@@ -243,15 +226,14 @@ my_listen(isc_task_t *task, isc_event_t *event)
isc_socket_detach(&oldsock); isc_socket_detach(&oldsock);
sockets_active--; sockets_active--;
ret = 1; isc_task_shutdown(task);
return;
} }
isc_event_free(&event); isc_event_free(&event);
return (ret);
} }
static isc_boolean_t static void
timeout(isc_task_t *task, isc_event_t *event) timeout(isc_task_t *task, isc_event_t *event)
{ {
isc_socket_t *sock = event->arg; isc_socket_t *sock = event->arg;
@@ -260,8 +242,6 @@ timeout(isc_task_t *task, isc_event_t *event)
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_ALL); isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_ALL);
isc_timer_detach((isc_timer_t **)&event->sender); isc_timer_detach((isc_timer_t **)&event->sender);
return (0);
} }
int int
@@ -296,10 +276,10 @@ main(int argc, char *argv[])
INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) == INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "1", 0, &t1) == INSIST(isc_task_create(manager, 0, &t1) == ISC_R_SUCCESS);
ISC_R_SUCCESS); INSIST(isc_task_create(manager, 0, &t2) == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "2", 0, &t2) == INSIST(isc_task_onshutdown(t1, my_shutdown, "1") == ISC_R_SUCCESS);
ISC_R_SUCCESS); INSIST(isc_task_onshutdown(t2, my_shutdown, "2") == ISC_R_SUCCESS);
printf("task 1 = %p\n", t1); printf("task 1 = %p\n", t1);
printf("task 2 = %p\n", t2); printf("task 2 = %p\n", t2);

View File

@@ -30,7 +30,7 @@
isc_memctx_t *mctx = NULL; isc_memctx_t *mctx = NULL;
static isc_boolean_t static void
my_callback(isc_task_t *task, isc_event_t *event) my_callback(isc_task_t *task, isc_event_t *event)
{ {
int i, j; int i, j;
@@ -41,29 +41,23 @@ my_callback(isc_task_t *task, isc_event_t *event)
j += 100; j += 100;
printf("task %s (%p): %d\n", name, task, j); printf("task %s (%p): %d\n", name, task, j);
isc_event_free(&event); isc_event_free(&event);
return (ISC_FALSE);
} }
static isc_boolean_t static void
my_shutdown(isc_task_t *task, isc_event_t *event) { my_shutdown(isc_task_t *task, isc_event_t *event) {
char *name = event->arg; char *name = event->arg;
printf("shutdown %s (%p)\n", name, task); printf("shutdown %s (%p)\n", name, task);
isc_event_free(&event); isc_event_free(&event);
return (ISC_TRUE);
} }
static isc_boolean_t static void
my_tick(isc_task_t *task, isc_event_t *event) my_tick(isc_task_t *task, isc_event_t *event)
{ {
char *name = event->arg; char *name = event->arg;
printf("task %p tick %s\n", task, name); printf("task %p tick %s\n", task, name);
isc_event_free(&event); isc_event_free(&event);
return (ISC_FALSE);
} }
void void
@@ -89,14 +83,15 @@ main(int argc, char *argv[]) {
INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) == INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "1", 0, &t1) == INSIST(isc_task_create(manager, 0, &t1) == ISC_R_SUCCESS);
ISC_R_SUCCESS); INSIST(isc_task_create(manager, 0, &t2) == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "2", 0, &t2) == INSIST(isc_task_create(manager, 0, &t3) == ISC_R_SUCCESS);
ISC_R_SUCCESS); INSIST(isc_task_create(manager, 0, &t4) == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "3", 0, &t3) ==
ISC_R_SUCCESS); INSIST(isc_task_onshutdown(t1, my_shutdown, "1") == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "4", 0, &t4) == INSIST(isc_task_onshutdown(t2, my_shutdown, "2") == ISC_R_SUCCESS);
ISC_R_SUCCESS); INSIST(isc_task_onshutdown(t3, my_shutdown, "3") == ISC_R_SUCCESS);
INSIST(isc_task_onshutdown(t4, my_shutdown, "4") == ISC_R_SUCCESS);
timgr = NULL; timgr = NULL;
INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS); INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS);

View File

@@ -33,17 +33,15 @@ isc_task_t *t1, *t2, *t3;
isc_timer_t *ti1, *ti2, *ti3; isc_timer_t *ti1, *ti2, *ti3;
int tick_count = 0; int tick_count = 0;
static isc_boolean_t static void
shutdown_task(isc_task_t *task, isc_event_t *event) { shutdown_task(isc_task_t *task, isc_event_t *event) {
char *name = event->arg; char *name = event->arg;
printf("task %p shutdown %s\n", task, name); printf("task %p shutdown %s\n", task, name);
isc_event_free(&event); isc_event_free(&event);
return (ISC_TRUE);
} }
static isc_boolean_t static void
tick(isc_task_t *task, isc_event_t *event) tick(isc_task_t *task, isc_event_t *event)
{ {
char *name = event->arg; char *name = event->arg;
@@ -71,11 +69,9 @@ tick(isc_task_t *task, isc_event_t *event)
} }
isc_event_free(&event); isc_event_free(&event);
return (ISC_FALSE);
} }
static isc_boolean_t static void
timeout(isc_task_t *task, isc_event_t *event) timeout(isc_task_t *task, isc_event_t *event)
{ {
char *name = event->arg; char *name = event->arg;
@@ -93,12 +89,11 @@ timeout(isc_task_t *task, isc_event_t *event)
if (strcmp(name, "3") == 0) { if (strcmp(name, "3") == 0) {
printf("*** saving task 3 ***\n"); printf("*** saving task 3 ***\n");
isc_event_free(&event); isc_event_free(&event);
return (ISC_FALSE); return;
} }
isc_event_free(&event); isc_event_free(&event);
isc_task_shutdown(task);
return (ISC_TRUE);
} }
void void
@@ -118,14 +113,15 @@ main(int argc, char *argv[]) {
INSIST(isc_memctx_create(0, 0, &mctx) == ISC_R_SUCCESS); INSIST(isc_memctx_create(0, 0, &mctx) == ISC_R_SUCCESS);
INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) == INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);
INSIST(isc_task_create(manager, shutdown_task, "1", 0, &t1) ==
ISC_R_SUCCESS);
INSIST(isc_task_create(manager, shutdown_task, "2", 0, &t2) ==
ISC_R_SUCCESS);
INSIST(isc_task_create(manager, shutdown_task, "3", 0, &t3) ==
ISC_R_SUCCESS);
INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS); INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, 0, &t1) == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, 0, &t2) == ISC_R_SUCCESS);
INSIST(isc_task_create(manager, 0, &t3) == ISC_R_SUCCESS);
INSIST(isc_task_onshutdown(t1, shutdown_task, "1") == ISC_R_SUCCESS);
INSIST(isc_task_onshutdown(t2, shutdown_task, "2") == ISC_R_SUCCESS);
INSIST(isc_task_onshutdown(t3, shutdown_task, "3") == ISC_R_SUCCESS);
printf("task 1: %p\n", t1); printf("task 1: %p\n", t1);
printf("task 2: %p\n", t2); printf("task 2: %p\n", t2);
printf("task 3: %p\n", t3); printf("task 3: %p\n", t3);

View File

@@ -163,10 +163,10 @@ static void free_socket(isc_socket_t **);
static isc_result_t allocate_socket(isc_socketmgr_t *, isc_sockettype_t, static isc_result_t allocate_socket(isc_socketmgr_t *, isc_sockettype_t,
isc_socket_t **); isc_socket_t **);
static void destroy(isc_socket_t **); static void destroy(isc_socket_t **);
static isc_boolean_t internal_accept(isc_task_t *, isc_event_t *); static void internal_accept(isc_task_t *, isc_event_t *);
static isc_boolean_t internal_connect(isc_task_t *, isc_event_t *); static void internal_connect(isc_task_t *, isc_event_t *);
static isc_boolean_t internal_recv(isc_task_t *, isc_event_t *); static void internal_recv(isc_task_t *, isc_event_t *);
static isc_boolean_t internal_send(isc_task_t *, isc_event_t *); static void internal_send(isc_task_t *, isc_event_t *);
#define SELECT_POKE_SHUTDOWN (-1) #define SELECT_POKE_SHUTDOWN (-1)
#define SELECT_POKE_NOTHING (-2) #define SELECT_POKE_NOTHING (-2)
@@ -307,8 +307,6 @@ done_event_destroy(isc_event_t *ev)
if (kill_socket) if (kill_socket)
destroy(&sock); destroy(&sock);
/* XXXRTH looks like we're leaking the done event here... */
} }
/* /*
@@ -692,7 +690,7 @@ send_ncdone_event(ncintev_t **iev,
* message, and once for the message itself) so the task does not need to * message, and once for the message itself) so the task does not need to
* attach to the socket again. The task is not attached at all. * attach to the socket again. The task is not attached at all.
*/ */
static isc_boolean_t static void
internal_accept(isc_task_t *task, isc_event_t *ev) internal_accept(isc_task_t *task, isc_event_t *ev)
{ {
isc_socket_t *sock; isc_socket_t *sock;
@@ -733,7 +731,7 @@ internal_accept(isc_task_t *task, isc_event_t *ev)
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_FALSE); return;
} }
/* /*
@@ -747,7 +745,7 @@ internal_accept(isc_task_t *task, isc_event_t *ev)
if (SOFT_ERROR(errno)) { if (SOFT_ERROR(errno)) {
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_FALSE); return;
} }
/* /*
@@ -817,11 +815,9 @@ internal_accept(isc_task_t *task, isc_event_t *ev)
} }
send_ncdone_event(&iev, &dev, result); send_ncdone_event(&iev, &dev, result);
return (ISC_FALSE);
} }
static isc_boolean_t static void
internal_recv(isc_task_t *task, isc_event_t *ev) internal_recv(isc_task_t *task, isc_event_t *ev)
{ {
rwintev_t *iev; rwintev_t *iev;
@@ -977,11 +973,9 @@ internal_recv(isc_task_t *task, isc_event_t *ev)
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_FALSE);
} }
static isc_boolean_t static void
internal_send(isc_task_t *task, isc_event_t *ev) internal_send(isc_task_t *task, isc_event_t *ev)
{ {
rwintev_t *iev; rwintev_t *iev;
@@ -1113,8 +1107,6 @@ internal_send(isc_task_t *task, isc_event_t *ev)
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_FALSE);
} }
/* /*
@@ -2095,7 +2087,7 @@ isc_socket_connect(isc_socket_t *sock, isc_sockaddr_t *addr, int addrlen,
/* /*
* Called when a socket with a pending connect() finishes. * Called when a socket with a pending connect() finishes.
*/ */
static isc_boolean_t static void
internal_connect(isc_task_t *task, isc_event_t *ev) internal_connect(isc_task_t *task, isc_event_t *ev)
{ {
isc_socket_t *sock; isc_socket_t *sock;
@@ -2127,7 +2119,7 @@ internal_connect(isc_task_t *task, isc_event_t *ev)
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_FALSE); return;
} }
dev = iev->done_ev; dev = iev->done_ev;
@@ -2152,7 +2144,7 @@ internal_connect(isc_task_t *task, isc_event_t *ev)
select_poke(sock->manager, sock->fd); select_poke(sock->manager, sock->fd);
UNLOCK(&sock->lock); UNLOCK(&sock->lock);
return (ISC_FALSE); return;
} }
/* /*
@@ -2183,8 +2175,6 @@ internal_connect(isc_task_t *task, isc_event_t *ev)
ISC_TASK_SEND(iev->task, (isc_event_t **)&dev); ISC_TASK_SEND(iev->task, (isc_event_t **)&dev);
iev->done_ev = NULL; iev->done_ev = NULL;
isc_event_free((isc_event_t **)&iev); isc_event_free((isc_event_t **)&iev);
return (ISC_FALSE);
} }
isc_result_t isc_result_t