2 * ParaZ - a simple tool for harvesting performance data for parallel
3 * operations using Z39.50.
4 * Copyright (c) 2000-2004 Index Data ApS
5 * See LICENSE file for details.
9 * $Id: eventl.c,v 1.2 2007-01-08 12:43:41 adam Exp $
10 * Based on revision YAZ' server/eventl.c 1.29.
29 #include <yaz/yconfig.h>
31 #include <yaz/comstack.h>
32 #include <yaz/xmalloc.h>
34 #include <yaz/statserv.h>
36 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
40 if (!(new_iochan = (IOCHAN)xmalloc(sizeof(*new_iochan))))
42 new_iochan->destroyed = 0;
44 new_iochan->flags = flags;
46 new_iochan->force_event = 0;
47 new_iochan->last_event = new_iochan->max_idle = 0;
48 new_iochan->next = NULL;
52 int event_loop(IOCHAN *iochans)
54 do /* loop as long as there are active associations to process */
57 fd_set in, out, except;
59 static struct timeval nullto = {0, 0}, to;
60 struct timeval *timeout;
65 timeout = &to; /* hang on select */
69 for (p = *iochans; p; p = p->next)
74 timeout = &nullto; /* polling select */
75 if (p->flags & EVENT_INPUT)
77 if (p->flags & EVENT_OUTPUT)
79 if (p->flags & EVENT_EXCEPT)
80 FD_SET(p->fd, &except);
84 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
91 for (p = *iochans; p; p = p->next)
93 int force_event = p->force_event;
97 if (!p->destroyed && ((p->max_idle && now - p->last_event >
98 p->max_idle) || force_event == EVENT_TIMEOUT))
101 (*p->fun)(p, EVENT_TIMEOUT);
105 if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
106 force_event == EVENT_INPUT))
109 (*p->fun)(p, EVENT_INPUT);
111 if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
112 force_event == EVENT_OUTPUT))
115 (*p->fun)(p, EVENT_OUTPUT);
117 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
118 force_event == EVENT_EXCEPT))
121 (*p->fun)(p, EVENT_EXCEPT);
124 for (p = *iochans; p; p = nextp)
132 /* Now reset the pointers */
137 for (pr = *iochans; pr; pr = pr->next)
140 assert(pr); /* grave error if it weren't there */
156 * indent-tabs-mode: nil
158 * vim: shiftwidth=4 tabstop=8 expandtab