Explorar el Código

BThreadWork: make pipe read end non-blocking

ambrop7 hace 15 años
padre
commit
9213aa8373
Se han modificado 1 ficheros con 7 adiciones y 0 borrados
  1. 7 0
      threadwork/BThreadWork.c

+ 7 - 0
threadwork/BThreadWork.c

@@ -25,6 +25,7 @@
 #ifdef BADVPN_THREADWORK_USE_PTHREAD
     #include <unistd.h>
     #include <errno.h>
+    #include <fcntl.h>
 #endif
 
 #include <misc/offset.h>
@@ -168,6 +169,12 @@ int BThreadWorkDispatcher_Init (BThreadWorkDispatcher *o, BReactor *reactor, int
             goto fail2;
         }
         
+        // set read end non-blocking
+        if (fcntl(o->pipe[0], F_SETFL, O_NONBLOCK) < 0) {
+            BLog(BLOG_ERROR, "pipe failed");
+            goto fail3;
+        }
+        
         // init BFileDescriptor
         BFileDescriptor_Init(&o->bfd, o->pipe[0], (BFileDescriptor_handler)pipe_fd_handler, o);
         if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {