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.1 2006-12-20 20:47:16 quinn Exp $
10 * Based on revision YAZ' server/eventl.c 1.29.
24 #include <yaz/yconfig.h>
26 #include <yaz/comstack.h>
27 #include <yaz/xmalloc.h>
29 #include <yaz/statserv.h>
31 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
35 if (!(new_iochan = (IOCHAN)xmalloc(sizeof(*new_iochan))))
37 new_iochan->destroyed = 0;
39 new_iochan->flags = flags;
41 new_iochan->force_event = 0;
42 new_iochan->last_event = new_iochan->max_idle = 0;
43 new_iochan->next = NULL;
47 int event_loop(IOCHAN *iochans)
49 do /* loop as long as there are active associations to process */
52 fd_set in, out, except;
54 static struct timeval nullto = {0, 0}, to;
55 struct timeval *timeout;
60 timeout = &to; /* hang on select */
64 for (p = *iochans; p; p = p->next)
69 timeout = &nullto; /* polling select */
70 if (p->flags & EVENT_INPUT)
72 if (p->flags & EVENT_OUTPUT)
74 if (p->flags & EVENT_EXCEPT)
75 FD_SET(p->fd, &except);
79 if ((res = select(max + 1, &in, &out, &except, timeout)) < 0)
86 for (p = *iochans; p; p = p->next)
88 int force_event = p->force_event;
92 if (!p->destroyed && ((p->max_idle && now - p->last_event >
93 p->max_idle) || force_event == EVENT_TIMEOUT))
96 (*p->fun)(p, EVENT_TIMEOUT);
100 if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
101 force_event == EVENT_INPUT))
104 (*p->fun)(p, EVENT_INPUT);
106 if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
107 force_event == EVENT_OUTPUT))
110 (*p->fun)(p, EVENT_OUTPUT);
112 if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
113 force_event == EVENT_EXCEPT))
116 (*p->fun)(p, EVENT_EXCEPT);
119 for (p = *iochans; p; p = nextp)
127 /* Now reset the pointers */
132 for (pr = *iochans; pr; pr = pr->next)
135 assert(pr); /* grave error if it weren't there */
151 * indent-tabs-mode: nil
153 * vim: shiftwidth=4 tabstop=8 expandtab