2 * Copyright (c) 1995, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1995-08-29 11:17:56 quinn
8 * Added code to receive close
10 * Revision 1.12 1995/08/29 10:41:18 quinn
13 * Revision 1.11 1995/06/19 12:39:09 quinn
14 * Fixed bug in timeout code. Added BER dumper.
16 * Revision 1.10 1995/06/16 10:31:33 quinn
17 * Added session timeout.
19 * Revision 1.9 1995/06/05 10:53:31 quinn
20 * Added a better SCAN.
22 * Revision 1.8 1995/05/16 08:51:01 quinn
23 * License, documentation, and memory fixes
25 * Revision 1.7 1995/03/27 15:02:01 quinn
26 * Added some includes for better portability
28 * Revision 1.6 1995/03/27 08:34:21 quinn
29 * Added dynamic server functionality.
30 * Released bindings to session.c (is now redundant)
32 * Revision 1.5 1995/03/15 08:37:41 quinn
33 * Now we're pretty much set for nonblocking I/O.
35 * Revision 1.4 1995/03/14 16:59:48 quinn
38 * Revision 1.3 1995/03/14 11:30:14 quinn
41 * Revision 1.2 1995/03/14 10:27:59 quinn
42 * More work on demo server.
44 * Revision 1.1 1995/03/10 18:22:44 quinn
45 * The rudiments of an asynchronous server.
51 #include <sys/types.h>
57 #include <sys/select.h>
64 static IOCHAN iochans = 0;
66 IOCHAN iochan_getchan(void)
71 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
75 if (!(new = malloc(sizeof(*new))))
83 new->last_event = new->max_idle = 0;
93 fd_set in, out, except;
95 static struct timeval nullto = {0, 0}, to;
96 struct timeval *timeout;
101 timeout = &to; /* hang on select */
102 to.tv_sec = 10/*5*60*/;
105 for (p = iochans; p; p = p->next)
108 timeout = &nullto; /* polling select */
109 if (p->flags & EVENT_INPUT)
111 if (p->flags & EVENT_OUTPUT)
113 if (p->flags & EVENT_EXCEPT)
114 FD_SET(p->fd, &except);
118 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
124 for (p = iochans; p; p = p->next)
126 int force_event = p->force_event;
127 time_t now = time(0);
130 if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT)
133 (*p->fun)(p, EVENT_INPUT);
135 if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
136 force_event == EVENT_OUTPUT))
139 (*p->fun)(p, EVENT_OUTPUT);
141 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
142 force_event == EVENT_EXCEPT))
145 (*p->fun)(p, EVENT_EXCEPT);
147 if (!p->destroyed && p->max_idle && now - p->last_event >
151 (*p->fun)(p, EVENT_TIMEOUT);
154 for (p = iochans; p; p = nextp)
166 for (pr = iochans; pr; pr = pr->next)
169 assert(pr); /* grave error if it weren't there */