2 * Copyright (c) 1995, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.18 1995-11-13 09:27:41 quinn
8 * Fiddling with the variant stuff.
10 * Revision 1.17 1995/11/07 12:37:44 quinn
11 * Added support for forcing TIMEOUT event.
13 * Revision 1.16 1995/11/01 13:54:56 quinn
16 * Revision 1.15 1995/09/15 14:44:15 quinn
17 * *** empty log message ***
19 * Revision 1.14 1995/08/29 14:44:50 quinn
22 * Revision 1.13 1995/08/29 11:17:56 quinn
23 * Added code to receive close
25 * Revision 1.12 1995/08/29 10:41:18 quinn
28 * Revision 1.11 1995/06/19 12:39:09 quinn
29 * Fixed bug in timeout code. Added BER dumper.
31 * Revision 1.10 1995/06/16 10:31:33 quinn
32 * Added session timeout.
34 * Revision 1.9 1995/06/05 10:53:31 quinn
35 * Added a better SCAN.
37 * Revision 1.8 1995/05/16 08:51:01 quinn
38 * License, documentation, and memory fixes
40 * Revision 1.7 1995/03/27 15:02:01 quinn
41 * Added some includes for better portability
43 * Revision 1.6 1995/03/27 08:34:21 quinn
44 * Added dynamic server functionality.
45 * Released bindings to session.c (is now redundant)
47 * Revision 1.5 1995/03/15 08:37:41 quinn
48 * Now we're pretty much set for nonblocking I/O.
50 * Revision 1.4 1995/03/14 16:59:48 quinn
53 * Revision 1.3 1995/03/14 11:30:14 quinn
56 * Revision 1.2 1995/03/14 10:27:59 quinn
57 * More work on demo server.
59 * Revision 1.1 1995/03/10 18:22:44 quinn
60 * The rudiments of an asynchronous server.
67 #include <sys/types.h>
73 #include <sys/select.h>
80 static IOCHAN iochans = 0;
82 IOCHAN iochan_getchan(void)
87 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
91 if (!(new = xmalloc(sizeof(*new))))
99 new->last_event = new->max_idle = 0;
106 do /* loop as long as there are active associations to process */
109 fd_set in, out, except;
111 static struct timeval nullto = {0, 0}, to;
112 struct timeval *timeout;
117 timeout = &to; /* hang on select */
121 for (p = iochans; p; p = p->next)
124 timeout = &nullto; /* polling select */
125 if (p->flags & EVENT_INPUT)
127 if (p->flags & EVENT_OUTPUT)
129 if (p->flags & EVENT_EXCEPT)
130 FD_SET(p->fd, &except);
134 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
140 for (p = iochans; p; p = p->next)
142 int force_event = p->force_event;
143 time_t now = time(0);
146 if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT)
149 (*p->fun)(p, EVENT_INPUT);
151 if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
152 force_event == EVENT_OUTPUT))
155 (*p->fun)(p, EVENT_OUTPUT);
157 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
158 force_event == EVENT_EXCEPT))
161 (*p->fun)(p, EVENT_EXCEPT);
163 if (!p->destroyed && (p->max_idle && now - p->last_event >
164 p->max_idle) || force_event == EVENT_TIMEOUT)
167 (*p->fun)(p, EVENT_TIMEOUT);
170 for (p = iochans; p; p = nextp)
182 for (pr = iochans; pr; pr = pr->next)
185 assert(pr); /* grave error if it weren't there */