From: Fabrice Bellard Date: Mon, 9 Nov 2026 14:42:04 +0000 (+0100) Subject: quickjs-libc: JSWaker workaround when the pipe buffer is full (#605) X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=014389e048e40b3d8866c12241daf71a54ed5b14;p=quickjs.git quickjs-libc: JSWaker workaround when the pipe buffer is full (#605) --- diff --git a/quickjs-libc.c b/quickjs-libc.c index b9e855b..2cea4e9 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -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; } }