From 0774e79e4fb6262e41217c8e89eca3b0675ce2de Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 14 Oct 2021 13:57:51 -0500 Subject: [PATCH] Pass non-blocking pipes to subprocesses on non-windows platform. --- src/core/ev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/ev.c b/src/core/ev.c index 7b68a3ec..54a7a195 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -2558,15 +2558,16 @@ void janet_ev_sendto_string(JanetStream *stream, JanetString str, void *dest, in static volatile long PipeSerialNumber; #endif +/* + * mode = 0: both sides non-blocking. + * mode = 1: only read side non-blocking: write side sent to subprocess + * mode = 2: only write side non-blocking: read side sent to subprocess + */ int janet_make_pipe(JanetHandle handles[2], int mode) { #ifdef JANET_WINDOWS /* * On windows, the built in CreatePipe function doesn't support overlapped IO * so we lift from the windows source code and modify for our own version. - * - * mode = 0: both sides non-blocking. - * mode = 1: only read side non-blocking: write side sent to subprocess - * mode = 2: only write side non-blocking: read side sent to subprocess */ JanetHandle shandle, chandle; UCHAR PipeNameBuffer[MAX_PATH]; @@ -2616,10 +2617,9 @@ int janet_make_pipe(JanetHandle handles[2], int mode) { } return 0; #else - (void) mode; if (pipe(handles)) return -1; - if (fcntl(handles[0], F_SETFL, O_NONBLOCK)) goto error; - if (fcntl(handles[1], F_SETFL, O_NONBLOCK)) goto error; + if (mode != 2 && fcntl(handles[0], F_SETFL, O_NONBLOCK)) goto error; + if (mode != 1 && fcntl(handles[1], F_SETFL, O_NONBLOCK)) goto error; return 0; error: close(handles[0]);