Commit 5bc99df995ab76d467e6f427c95019a98cf31048

Thomas de Grivel 2017-06-27T18:06:44

support optional self-pipe in acceptor loop

diff --git a/thot-simple.lisp b/thot-simple.lisp
index 0b938f7..b7a1c15 100644
--- a/thot-simple.lisp
+++ b/thot-simple.lisp
@@ -1,16 +1,21 @@
 
 (in-package :thot)
 
-(defun acceptor-loop-simple (fd)
+(defun acceptor-loop-simple (fd &optional pipe)
   (declare (type (unsigned-byte 31) fd))
-  (labels ((acceptor-loop-simple-fun ()
-             (loop
-                (when *stop*
-                  (return))
-                (ignore-errors
-                  (unistd:with-selected (`(,fd) () () 1)
+  (let ((readfds))
+    (push fd readfds)
+    (when pipe
+      (push pipe readfds))
+    (labels ((acceptor-loop-simple-fun ()
+               (loop
+                  (when *stop*
+                    (return))
+                  (unistd:with-selected (readfds () () 100)
                       (readable writable errors)
-                    (when readable
+                    (when (and pipe (find pipe readable))
+                      (return))
+                    (when (find fd readable)
                       (socket:with-accept (clientfd) fd
                         (with-stream (stream (babel-io-stream
                                               (fd-io-stream clientfd)))