| 1213 | } |
| 1214 | |
| 1215 | Status SetPipeFileDescriptorNonBlocking(int fd) { |
| 1216 | #if defined(_WIN32) |
| 1217 | const auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd)); |
| 1218 | DWORD mode = PIPE_NOWAIT; |
| 1219 | if (!SetNamedPipeHandleState(handle, &mode, nullptr, nullptr)) { |
| 1220 | return IOErrorFromWinError(GetLastError(), "Error making pipe non-blocking"); |
| 1221 | } |
| 1222 | #else |
| 1223 | int flags = fcntl(fd, F_GETFL); |
| 1224 | if (flags == -1 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { |
| 1225 | return IOErrorFromErrno(errno, "Error making pipe non-blocking"); |
| 1226 | } |
| 1227 | #endif |
| 1228 | return Status::OK(); |
| 1229 | } |
| 1230 | |
| 1231 | namespace { |
| 1232 | |