2 * Copyright (c) 1995, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1995-05-16 08:51:01 quinn
8 * License, documentation, and memory fixes
10 * Revision 1.7 1995/03/27 15:02:01 quinn
11 * Added some includes for better portability
13 * Revision 1.6 1995/03/27 08:34:21 quinn
14 * Added dynamic server functionality.
15 * Released bindings to session.c (is now redundant)
17 * Revision 1.5 1995/03/15 08:37:41 quinn
18 * Now we're pretty much set for nonblocking I/O.
20 * Revision 1.4 1995/03/14 16:59:48 quinn
23 * Revision 1.3 1995/03/14 11:30:14 quinn
26 * Revision 1.2 1995/03/14 10:27:59 quinn
27 * More work on demo server.
29 * Revision 1.1 1995/03/10 18:22:44 quinn
30 * The rudiments of an asynchronous server.
36 #include <sys/types.h>
46 static IOCHAN iochans = 0;
48 IOCHAN iochan_getchan(void)
53 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
57 if (!(new = malloc(sizeof(*new))))
74 fd_set in, out, except;
76 static struct timeval nullto = {0, 0};
77 struct timeval *timeout;
82 timeout = 0; /* hang on select */
84 for (p = iochans; p; p = p->next)
88 if (p->flags & EVENT_INPUT)
90 if (p->flags & EVENT_OUTPUT)
92 if (p->flags & EVENT_EXCEPT)
93 FD_SET(p->fd, &except);
97 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
103 for (p = iochans; p; p = p->next)
105 int force_event = p->force_event;
108 if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT)
109 (*p->fun)(p, EVENT_INPUT);
110 if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
111 force_event == EVENT_OUTPUT))
112 (*p->fun)(p, EVENT_OUTPUT);
113 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
114 force_event == EVENT_EXCEPT))
115 (*p->fun)(p, EVENT_EXCEPT);
117 for (p = iochans; p; p = nextp)
129 for (pr = iochans; pr; pr = pr->next)