2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-03-14 10:27:59 quinn
8 * More work on demo server.
10 * Revision 1.1 1995/03/10 18:22:44 quinn
11 * The rudiments of an asynchronous server.
17 #include <sys/types.h>
25 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
29 if (!(new = malloc(sizeof(*new))))
45 fd_set in, out, except;
47 static struct timeval nullto = {0, 0};
48 struct timeval *timeout;
53 timeout = 0; /* hang on select */
54 for (p = iochans; p; p = p->next)
58 if (p->flags & EVENT_INPUT)
60 if (p->flags & EVENT_OUTPUT)
62 if (p->flags & EVENT_EXCEPT)
63 FD_SET(p->fd, &except);
67 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
75 for (p = iochans; p; p = nextp)
77 int force_event = p->force_event;
81 if (FD_ISSET(p->fd, &in) || force_event == EVENT_INPUT)
82 (*p->fun)(p, EVENT_INPUT);
83 if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
84 force_event == EVENT_OUTPUT))
85 (*p->fun)(p, EVENT_OUTPUT);
86 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
87 force_event == EVENT_EXCEPT))
88 (*p->fun)(p, EVENT_EXCEPT);
97 for (pr = iochans; pr; pr = pr->next)