2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-03-14 11:30:14 quinn
10 * Revision 1.2 1995/03/14 10:27:59 quinn
11 * More work on demo server.
13 * Revision 1.1 1995/03/10 18:22:44 quinn
14 * The rudiments of an asynchronous server.
20 #include <sys/types.h>
28 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
32 if (!(new = malloc(sizeof(*new))))
48 fd_set in, out, except;
50 static struct timeval nullto = {0, 0};
51 struct timeval *timeout;
56 timeout = 0; /* hang on select */
58 for (p = iochans; p; p = p->next)
62 if (p->flags & EVENT_INPUT)
64 if (p->flags & EVENT_OUTPUT)
66 if (p->flags & EVENT_EXCEPT)
67 FD_SET(p->fd, &except);
71 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
79 for (p = iochans; p; p = nextp)
81 int force_event = p->force_event;
85 if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT)
86 (*p->fun)(p, EVENT_INPUT);
87 if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
88 force_event == EVENT_OUTPUT))
89 (*p->fun)(p, EVENT_OUTPUT);
90 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
91 force_event == EVENT_EXCEPT))
92 (*p->fun)(p, EVENT_EXCEPT);
101 for (pr = iochans; pr; pr = pr->next)