Skip to content

Commit 4338bb7

Browse files
PR feedback and don't overwrite other pipe mode flags.
1 parent 2084def commit 4338bb7

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/io.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,19 +1436,23 @@ _dispatch_fd_entry_create_with_fd(dispatch_fd_t fd, uintptr_t hash)
14361436
unsigned long value = 1;
14371437
int result = ioctlsocket((SOCKET)fd, (long)FIONBIO, &value);
14381438
(void)dispatch_assume_zero(result);
1439-
}
1440-
else {
1439+
} else {
14411440
// Try to make writing nonblocking, although pipes not coming
14421441
// from Foundation.Pipe may not have FILE_WRITE_ATTRIBUTES.
1443-
DWORD pipe_mode = PIPE_NOWAIT;
1444-
if (!SetNamedPipeHandleState((HANDLE)fd, &pipe_mode, NULL,
1445-
NULL)) {
1446-
// We may end up blocking on subsequent writes, but we
1447-
// don't have a good alternative. The WriteQuotaAvailable
1448-
// from NtQueryInformationFile erroneously returns 0 when
1449-
// there is a blocking read on the other end of the pipe.
1450-
_dispatch_fd_entry_debug("failed to set PIPE_NOWAIT",
1451-
fd_entry);
1442+
DWORD dwPipeMode = 0;
1443+
if (GetNamedPipeHandleState((HANDLE)fd, &dwPipeMode, NULL,
1444+
NULL, NULL, NULL, 0) && !(dwPipeMode & PIPE_NOWAIT)) {
1445+
dwPipeMode |= PIPE_NOWAIT;
1446+
if (!SetNamedPipeHandleState((HANDLE)fd, &dwPipeMode,
1447+
NULL, NULL)) {
1448+
// We may end up blocking on subsequent writes, but we
1449+
// don't have a good alternative.
1450+
// The WriteQuotaAvailable from NtQueryInformationFile
1451+
// erroneously returns 0 when there is a blocking read
1452+
// on the other end of the pipe.
1453+
_dispatch_fd_entry_debug("failed to set PIPE_NOWAIT",
1454+
fd_entry);
1455+
}
14521456
}
14531457
}
14541458

0 commit comments

Comments
 (0)