- * $Id: eventl.c,v 1.1 2003-10-27 12:21:30 adam Exp $
+ * $Id: eventl.c,v 1.9 2005-06-25 15:46:04 adam Exp $
+ */
+
+/**
+ * \file eventl.c
+ * \brief Implements event loop handling for GFS.
+ *
+ * This source implements the main event loop for the Generic Frontend
+ * Server. It uses select(2).
-IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags)
+static int log_level=0;
+static int log_level_initialized=0;
+
+IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, int chan_id)
- IOCHAN p, nextp;
- fd_set in, out, except;
- int res, max;
- static struct timeval to;
+ IOCHAN p, nextp;
+ fd_set in, out, except;
+ int res, max;
+ static struct timeval to;
- if (p->flags & EVENT_INPUT)
- FD_SET(p->fd, &in);
- if (p->flags & EVENT_OUTPUT)
- FD_SET(p->fd, &out);
- if (p->flags & EVENT_EXCEPT)
- FD_SET(p->fd, &except);
- if (p->fd > max)
- max = p->fd;
+ if (p->flags & EVENT_INPUT)
+ FD_SET(p->fd, &in);
+ if (p->flags & EVENT_OUTPUT)
+ FD_SET(p->fd, &out);
+ if (p->flags & EVENT_EXCEPT)
+ FD_SET(p->fd, &except);
+ if (p->fd > max)
+ max = p->fd;
- }
- yaz_log(LOG_DEBUG, "select start %ld", (long) to.tv_sec);
- res = YAZ_EV_SELECT(max + 1, &in, &out, &except, &to);
- yaz_log(LOG_DEBUG, "select end");
- if (res < 0)
- {
- if (yaz_errno() == EINTR)
+ }
+ yaz_log(log_level, "select start %ld", (long) to.tv_sec);
+ res = YAZ_EV_SELECT(max + 1, &in, &out, &except, &to);
+ yaz_log(log_level, "select end");
+ if (res < 0)
+ {
+ if (yaz_errno() == EINTR)
- destroy_association(assoc);
- iochan_destroy(*iochans);
- yaz_log(LOG_DEBUG, "error select, destroying iochan %p",
- *iochans);
+ destroy_association(assoc);
+ iochan_destroy(*iochans);
+ yaz_log(log_level, "error select, destroying iochan %p",
+ *iochans);
- for (p = *iochans; p; p = p->next)
- {
- int force_event = p->force_event;
-
- p->force_event = 0;
- if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
- force_event == EVENT_INPUT))
- {
- p->last_event = now;
- (*p->fun)(p, EVENT_INPUT);
- }
- if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
- force_event == EVENT_OUTPUT))
- {
- p->last_event = now;
- (*p->fun)(p, EVENT_OUTPUT);
- }
- if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
- force_event == EVENT_EXCEPT))
- {
- p->last_event = now;
- (*p->fun)(p, EVENT_EXCEPT);
- }
- if (!p->destroyed && ((p->max_idle && now - p->last_event >=
- p->max_idle) || force_event == EVENT_TIMEOUT))
- {
- p->last_event = now;
- (*p->fun)(p, EVENT_TIMEOUT);
- }
- }
- for (p = *iochans; p; p = nextp)
- {
- nextp = p->next;
-
- if (p->destroyed)
- {
- IOCHAN tmp = p, pr;
+ for (p = *iochans; p; p = p->next)
+ {
+ int force_event = p->force_event;
+
+ p->force_event = 0;
+ if (!p->destroyed && (FD_ISSET(p->fd, &in) ||
+ force_event == EVENT_INPUT))
+ {
+ p->last_event = now;
+ (*p->fun)(p, EVENT_INPUT);
+ }
+ if (!p->destroyed && (FD_ISSET(p->fd, &out) ||
+ force_event == EVENT_OUTPUT))
+ {
+ p->last_event = now;
+ (*p->fun)(p, EVENT_OUTPUT);
+ }
+ if (!p->destroyed && (FD_ISSET(p->fd, &except) ||
+ force_event == EVENT_EXCEPT))
+ {
+ p->last_event = now;
+ (*p->fun)(p, EVENT_EXCEPT);
+ }
+ if (!p->destroyed && ((p->max_idle && now - p->last_event >=
+ p->max_idle) || force_event == EVENT_TIMEOUT))
+ {
+ p->last_event = now;
+ (*p->fun)(p, EVENT_TIMEOUT);
+ }
+ }
+ for (p = *iochans; p; p = nextp)
+ {
+ nextp = p->next;
+
+ if (p->destroyed)
+ {
+ IOCHAN tmp = p, pr;