Fixes to improve portability (especially to OS X, Solaris, OpenBSD).
[ircu2.10.12-pk.git] / ircd / engine_poll.c
index aa8dc2ab6f98e0a987e53defd73028fdfa68b8fe..fe52249bc76181b95f55fb6fac2ab406ffb14159 100644 (file)
 #  define POLLWRITEFLAGS POLLWRNORM
 #endif
 
-/* Figure out what bits indicate errors */
-#ifdef POLLHUP
-#  define POLLERRORS (POLLHUP|POLLERR)
-#else
-#  define POLLERRORS POLLERR
-#endif
-
 static struct Socket** sockList;
 static struct pollfd* pollfdList;
 static unsigned int poll_count;
@@ -251,7 +244,7 @@ engine_loop(struct Generators* gen)
   int nfds;
   int i;
   int errcode;
-  size_t codesize;
+  socklen_t codesize;
   struct Socket *sock;
 
   while (running) {
@@ -270,7 +263,7 @@ engine_loop(struct Generators* gen)
        /* Log the poll error */
        log_write(LS_SOCKET, L_ERROR, 0, "poll() error: %m");
        if (!errors++)
-         timer_add(&clear_error, error_clear, 0, TT_PERIODIC,
+         timer_add(timer_init(&clear_error), error_clear, 0, TT_PERIODIC,
                    ERROR_EXPIRE_TIME);
        else if (errors > POLL_ERROR_THRESHOLD) /* too many errors... */
          server_restart("too many poll errors");
@@ -310,6 +303,15 @@ engine_loop(struct Generators* gen)
        }
       }
 
+#ifdef POLLHUP
+      if (pollfdList[i].revents & POLLHUP) { /* hang-up on socket */
+       Debug((DEBUG_ENGINE, "poll: EOF from client (POLLHUP)"));
+       event_generate(ET_EOF, sock, 0);
+       nfds--;
+       continue;
+      }
+#endif /* POLLHUP */
+
       switch (s_state(sock)) {
       case SS_CONNECTING:
        if (pollfdList[i].revents & POLLWRITEFLAGS) { /* connect completed */
@@ -383,8 +385,6 @@ engine_loop(struct Generators* gen)
        break;
       }
 
-      assert(s_fd(sock) == pollfdList[i].fd);
-
       gen_ref_dec(sock); /* we're done with it */
     }