]> git.kaiwu.me - quickjs.git/commitdiff
quickjs-libc: JSWaker workaround when the pipe buffer is full (#605)
authorFabrice Bellard <fabrice@bellard.org>
Mon, 9 Nov 2026 14:42:04 +0000 (15:42 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Mon, 9 Nov 2026 14:42:04 +0000 (15:42 +0100)
quickjs-libc.c

index b9e855b9866d290c81bc4fe0cb8a5c0f50762a92..2cea4e9631f124b3f5a4586cbda2eea874d73a6e 100644 (file)
@@ -2369,6 +2369,8 @@ static int js_waker_init(JSWaker *w)
 
     if (pipe(fds) < 0)
         return -1;
+    fcntl(fds[0], F_SETFL, fcntl(fds[0], F_GETFL) | O_NONBLOCK);
+    fcntl(fds[1], F_SETFL, fcntl(fds[1], F_GETFL) | O_NONBLOCK);
     w->read_fd = fds[0];
     w->write_fd = fds[1];
     return 0;
@@ -2382,7 +2384,10 @@ static void js_waker_signal(JSWaker *w)
         ret = write(w->write_fd, "", 1);
         if (ret == 1)
             break;
-        if (ret < 0 && (errno != EAGAIN || errno != EINTR))
+        /* if errno = EAGAIN the pipe is full and we consider it is
+           likely that the poll() will be waked anyway, so we don't
+           need to block */
+        if (ret < 0 && errno != EINTR)
             break;
     }
 }