@@ -1436,19 +1436,23 @@ _dispatch_fd_entry_create_with_fd(dispatch_fd_t fd, uintptr_t hash)
1436
1436
unsigned long value = 1 ;
1437
1437
int result = ioctlsocket ((SOCKET )fd , (long )FIONBIO , & value );
1438
1438
(void )dispatch_assume_zero (result );
1439
- }
1440
- else {
1439
+ } else {
1441
1440
// Try to make writing nonblocking, although pipes not coming
1442
1441
// 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
+ }
1452
1456
}
1453
1457
}
1454
1458
0 commit comments