- 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);
- }
- }
- for (p = *iochans; p; p = nextp)
- {
- nextp = p->next;
-
- if (p->destroyed)
- {
- IOCHAN tmp = p, pr;
-
- /* Now reset the pointers */
- if (p == *iochans)
- *iochans = p->next;
- else
- {
- for (pr = *iochans; pr; pr = pr->next)
- if (pr->next == p)
- break;
- assert(pr); /* grave error if it weren't there */
- pr->next = p->next;
- }
- if (nextp == p)
- nextp = p->next;
- xfree(tmp);
- }
- }
- }
- while (*iochans);
+ 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(man->log_level, "max=%d sel_fd=%d", max, man->sel_fd);
+
+ if (man->sel_fd != -1) {
+ if (man->sel_fd > max)
+ max = man->sel_fd;
+ FD_SET(man->sel_fd, &in);
+ }
+ yaz_log(man->log_level, "select begin nofds=%d", max);
+ res = select(max + 1, &in, &out, &except, timeout);
+ yaz_log(man->log_level, "select returned res=%d", res);
+ if (res < 0) {
+ if (errno == EINTR)
+ continue;
+ else {
+ yaz_log(YLOG_ERRNO | YLOG_WARN, "select");
+ return 0;
+ }
+ }
+ if (man->sel_fd != -1) {
+ if (FD_ISSET(man->sel_fd, &in)) {
+ IOCHAN chan;
+
+ yaz_log(man->log_level, "eventl: sel input on sel_fd=%d",
+ man->sel_fd);
+ while ((chan = sel_thread_result(man->sel_thread))) {
+ yaz_log(man->log_level,
+ "eventl: got thread result chan=%p name=%s", chan,
+ chan->name ? chan->name : "");
+ chan->thread_users--;
+ }
+ }
+ }
+ if (man->log_level) {
+ int no = 0;
+ for (p = start; p; p = p->next) {
+ no++;
+ }
+ yaz_log(man->log_level, "%d channels", no);
+ }
+ for (p = start; p; p = p->next) {
+ time_t now = time(0);
+
+ if (p->destroyed) {
+ yaz_log(man->log_level,
+ "eventl: skip destroyed chan=%p name=%s", p,
+ p->name ? p->name : "");
+ continue;
+ }
+ if (p->thread_users > 0) {
+ yaz_log(man->log_level,
+ "eventl: skip chan=%p name=%s users=%d", p,
+ p->name ? p->name : "", p->thread_users);
+ continue;
+ }
+ p->this_event = 0;
+
+ if (p->max_idle && now - p->last_event > p->max_idle) {
+ p->last_event = now;
+ p->this_event |= EVENT_TIMEOUT;
+ }
+ if (p->fd >= 0) {
+ if (FD_ISSET(p->fd, &in)) {
+ p->last_event = now;
+ p->this_event |= EVENT_INPUT;
+ }
+ if (FD_ISSET(p->fd, &out)) {
+ p->last_event = now;
+ p->this_event |= EVENT_OUTPUT;
+ }
+ if (FD_ISSET(p->fd, &except)) {
+ p->last_event = now;
+ p->this_event |= EVENT_EXCEPT;
+ }
+ }
+ run_fun(man, p);
+ }
+ assert(inv_start == start);
+ yaz_mutex_enter(man->iochan_mutex);
+ for (nextp = iochans; *nextp;) {
+ IOCHAN p = *nextp;
+ if (p->destroyed && p->thread_users == 0) {
+ *nextp = iochan_destroy_real(p);
+ } else
+ nextp = &p->next;
+ }
+ yaz_mutex_leave(man->iochan_mutex);
+ } while (*iochans);