Commit 703fb237 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Support using fcntl to mark pipes as non-blocking

Summary: Because the comment was a lie; sockets are blocking by default, not non-blocking.

Reviewed By: yfeldblum

Differential Revision: D3691145

fbshipit-source-id: 5d3c62b3573205fe416d77fe4b5b9fbd593ffd93
parent 70618258
...@@ -60,8 +60,7 @@ int fcntl(int fd, int cmd, ...) { ...@@ -60,8 +60,7 @@ int fcntl(int fd, int cmd, ...) {
case F_SETFL: { case F_SETFL: {
int flags = va_arg(args, int); int flags = va_arg(args, int);
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
// If it's not a socket, it's probably a pipe, and // If it's not a socket, it's probably a pipe.
// those are non-blocking by default with Windows.
if (folly::portability::sockets::is_fh_socket(fd)) { if (folly::portability::sockets::is_fh_socket(fd)) {
SOCKET s = (SOCKET)_get_osfhandle(fd); SOCKET s = (SOCKET)_get_osfhandle(fd);
if (s != INVALID_SOCKET) { if (s != INVALID_SOCKET) {
...@@ -69,7 +68,13 @@ int fcntl(int fd, int cmd, ...) { ...@@ -69,7 +68,13 @@ int fcntl(int fd, int cmd, ...) {
res = ioctlsocket(s, FIONBIO, &nonBlockingEnabled); res = ioctlsocket(s, FIONBIO, &nonBlockingEnabled);
} }
} else { } else {
res = 0; HANDLE p = (HANDLE)_get_osfhandle(fd);
if (GetFileType(p) == FILE_TYPE_PIPE) {
DWORD newMode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
if (SetNamedPipeHandleState(p, &newMode, nullptr, nullptr)) {
res = 0;
}
}
} }
} }
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment