fix select EINTR issues
authorterom
Mon, 22 Dec 2008 02:36:28 +0000
changeset 384 6d387796b139
parent 383 2a57f0a871b0
child 385 e56af22c04dd
fix select EINTR issues
src/Network/Reactor.cc
--- a/src/Network/Reactor.cc	Wed Dec 17 01:13:26 2008 +0000
+++ b/src/Network/Reactor.cc	Mon Dec 22 02:36:28 2008 +0000
@@ -1,7 +1,6 @@
 
 #include "Reactor.hh"
 
-
 NetworkReactor::NetworkReactor (void) :
     sockets()
 {
@@ -9,6 +8,8 @@
 }
 
 void NetworkReactor::poll (timeval *timeout) {
+    int ret;
+
     // start counting the maximum fd from -1, so that select is given nfds=0 if our list is empty
     int fd_max = 0;
 
@@ -47,18 +48,20 @@
         }
     }
 
-    // run select
-    int ret;
-    
-    // we never care about except
-    // pass NULL fdsets if they are empty
-    if ((ret = select(
+    // loop select() on EINTR
+    do {
+        // we never care about except, and pass NULL fdsets if they are empty
+        ret = select(
             fd_max + 1, 
             fd_max ? &read : NULL, 
             fd_max ? &write : NULL, 
             NULL, 
             timeout
-    )) < 0)
+        );
+    } while (ret < 0 && errno == EINTR);
+    
+    // error?
+    if (ret < 0)
         throw NetworkReactorError("select");
     
     // ignore if we just timed out