Use IOCHAN for poll result inspection
[pazpar2-moved-to-github.git] / src / eventl.c
index 2808c07..b914bf3 100644 (file)
@@ -36,7 +36,9 @@
 #include <stdio.h>
 #include <assert.h>
 
+#if HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 
 #include <stdlib.h>
 #include <errno.h>
@@ -251,6 +253,7 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
         }
         for (p = start; p; p = p->next, i++)
         {
+            p->poll_offset = i;
             fds[i].client_data = p;
             fds[i].fd = p->fd;
             fds[i].input_mask = 0;
@@ -280,9 +283,9 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
                 return 0;
             }
         }
-        i = 0;
         if (man->sel_fd != -1)
         {
+            i = 0;
             assert(fds[i].fd == man->sel_fd);
             if (fds[i].output_mask)
             {
@@ -298,7 +301,6 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
                     chan->thread_users--;
                 }
             }
-            i++;
         }
         if (man->log_level)
         {
@@ -307,10 +309,10 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
                 no++;
             yaz_log(man->log_level, "%d channels", no);
         }
-        for (; i < no_fds; i++)
+        for (p = start; p; p = p->next)
         {
             time_t now = time(0);
-            p = fds[i].client_data;
+            i = p->poll_offset;
 
             if (p->destroyed)
             {