| 113 | } |
| 114 | |
| 115 | bool set_nonblocking(int fd, bool enabled) { |
| 116 | #ifdef FL_IS_WIN |
| 117 | u_long mode = enabled ? 1 : 0; |
| 118 | return ioctlsocket(fd, FIONBIO, &mode) == 0; |
| 119 | #else |
| 120 | int flags = fcntl(fd, F_GETFL, 0); |
| 121 | if (flags == -1) |
| 122 | return false; |
| 123 | if (enabled) { |
| 124 | return fcntl(fd, F_SETFL, flags | O_NONBLOCK) != -1; |
| 125 | } else { |
| 126 | return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) != -1; |
| 127 | } |
| 128 | #endif |
| 129 | } |
| 130 | |
| 131 | bool is_would_block() { |
| 132 | #ifdef FL_IS_WIN |
no test coverage detected