Commit 7f9e7076 authored by Michael Graff's avatar Michael Graff
Browse files

checkpoint

parent 1edb223d
......@@ -14,6 +14,8 @@
isc_memctx_t mctx = NULL;
volatile int tasks_done = 0;
static isc_boolean_t
my_callback(isc_task_t task, isc_event_t event)
{
......@@ -35,6 +37,20 @@ my_shutdown(isc_task_t task, isc_event_t event)
fflush(stdout);
isc_event_free(&event);
tasks_done++;
return (ISC_TRUE);
}
static isc_boolean_t
my_listen(isc_task_t task, isc_event_t event)
{
char *name = event->arg;
printf("newcon %s (%p)\n", name, task);
fflush(stdout);
isc_event_free(&event);
return (ISC_TRUE);
}
......@@ -43,11 +59,16 @@ main(int argc, char *argv[])
{
isc_taskmgr_t manager = NULL;
isc_task_t t1 = NULL, t2 = NULL;
isc_task_t t3 = NULL, t4 = NULL;
isc_event_t event;
unsigned int workers;
isc_socketmgr_t socketmgr;
isc_socket_t so1, so2;
struct isc_sockaddr sockaddr;
int addrlen;
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.type.sin.sin_port = htons(5544);
addrlen = sizeof(struct sockaddr_in);
if (argc > 1)
workers = atoi(argv[1]);
......@@ -64,23 +85,21 @@ main(int argc, char *argv[])
ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "2", 0, &t2) ==
ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "3", 0, &t3) ==
ISC_R_SUCCESS);
INSIST(isc_task_create(manager, my_shutdown, "4", 0, &t4) ==
ISC_R_SUCCESS);
printf("task 1 = %p\n", t1);
printf("task 2 = %p\n", t2);
printf("task 3 = %p\n", t3);
printf("task 4 = %p\n", t4);
socketmgr = NULL;
INSIST(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
so1 = NULL;
INSIST(isc_socket_create(socketmgr, isc_socket_udp,
INSIST(isc_socket_create(socketmgr, isc_socket_tcp,
&so1) == ISC_R_SUCCESS);
INSIST(isc_socket_bind(so1, &sockaddr, addrlen) == ISC_R_SUCCESS);
INSIST(isc_socket_listen(so1, 0, t1, my_listen,
"so1") == ISC_R_SUCCESS);
so2 = NULL;
INSIST(isc_socket_create(socketmgr, isc_socket_udp,
INSIST(isc_socket_create(socketmgr, isc_socket_tcp,
&so2) == ISC_R_SUCCESS);
sleep(2);
......@@ -115,29 +134,23 @@ main(int argc, char *argv[])
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "2",
sizeof *event);
isc_task_send(t2, &event);
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "3",
sizeof *event);
isc_task_send(t3, &event);
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "4",
sizeof *event);
isc_task_send(t4, &event);
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "2",
sizeof *event);
isc_task_send(t2, &event);
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "3",
sizeof *event);
isc_task_send(t3, &event);
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "4",
sizeof *event);
isc_task_send(t4, &event);
isc_task_purge(t3, NULL, 0);
isc_task_shutdown(t1);
isc_task_shutdown(t2);
isc_task_detach(&t1);
isc_task_detach(&t2);
isc_task_detach(&t3);
isc_task_detach(&t4);
sleep(10);
/*
* Grr! there is no way to say "wake me when it's over"
*/
while (tasks_done != 2) {
fprintf(stderr, "Tasks done: %d\n", tasks_done);
sleep(2);
}
printf("destroy\n");
isc_socket_detach(&so1);
isc_socket_detach(&so2);
......
/* $Id: socket.h,v 1.2 1998/11/06 01:45:35 explorer Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
......@@ -45,6 +46,7 @@
#include <isc/boolean.h>
#include <isc/result.h>
#include <isc/event.h>
#include <isc/task.h>
#include <isc/region.h>
......@@ -66,24 +68,34 @@ typedef struct isc_sockaddr {
/*
* XXX Must be big enough for all sockaddr types we care about.
*/
union foo {
union {
struct sockaddr_in sin;
};
} type;
} *isc_sockaddr_t;
typedef struct isc_sockevent {
typedef struct isc_socketevent {
struct isc_event common; /* Sender is the socket. */
isc_result_t result; /* OK, EOF, whatever else */
unsigned int n; /* bytes read or written */
struct isc_region region; /* the region info */
struct isc_sockaddr address; /* source address */
int length; /* length of address */
} *isc_sockevent_t;
int addrlength; /* length of address */
} *isc_socketevent_t;
#define ISC_SOCKEVENT_ANYEVENT (0)
#define ISC_SOCKEVENT_RECVDONE (EVENT_CLASS_SOCKET + 1)
#define ISC_SOCKEVENT_SENDDONE (EVENT_CLASS_SOCKET + 2)
#define ISC_SOCKEVENT_NEWCONN (EVENT_CLASS_SOCKET + 3)
#define ISC_SOCKEVENT_CONNECTED (EVENT_CLASS_SOCKET + 4)
#define ISC_SOCKEVENT_RECVDONE (ISC_EVENTCLASS_SOCKET + 1)
#define ISC_SOCKEVENT_SENDDONE (ISC_EVENTCLASS_SOCKET + 2)
#define ISC_SOCKEVENT_NEWCONN (ISC_EVENTCLASS_SOCKET + 3)
#define ISC_SOCKEVENT_CONNECTED (ISC_EVENTCLASS_SOCKET + 4)
#define ISC_SOCKEVENT_RECVMARK (ISC_EVENTCLASS_SOCKET + 5)
#define ISC_SOCKEVENT_SENDMARK (ISC_EVENTCLASS_SOCKET + 6)
/*
* Internal events.
*/
#define ISC_SOCKEVENT_INTIO (ISC_EVENTCLASS_SOCKET + 257)
#define ISC_SOCKEVENT_INTCONN (ISC_EVENTCLASS_SOCKET + 258)
typedef enum {
isc_socket_udp,
......@@ -213,7 +225,7 @@ isc_socket_detach(isc_socket_t *socketp);
*/
isc_result_t
net_socket_bind(isc_socket_t socket, struct isc_sockaddr *addressp,
isc_socket_bind(isc_socket_t socket, struct isc_sockaddr *addressp,
int length);
/*
* Bind 'socket' to '*addressp'.
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment