fcntl emulation for non-blocking sockets
| 276 | |
| 277 | // fcntl emulation for non-blocking sockets |
| 278 | int fcntl(int fd, int cmd, ...) FL_NOEXCEPT { |
| 279 | SOCKET sock = static_cast<SOCKET>(fd); |
| 280 | |
| 281 | if (cmd == F_GETFL) { |
| 282 | // Windows doesn't provide a way to query non-blocking status |
| 283 | // Return 0 (blocking) as default |
| 284 | return 0; |
| 285 | } else if (cmd == F_SETFL) { |
| 286 | va_list args; |
| 287 | va_start(args, cmd); |
| 288 | int flags = va_arg(args, int); |
| 289 | va_end(args); |
| 290 | |
| 291 | u_long mode = (flags & O_NONBLOCK) ? 1 : 0; |
| 292 | int result = ioctlsocket(sock, FIONBIO, &mode); |
| 293 | return (result == SOCKET_ERROR) ? -1 : 0; |
| 294 | } |
| 295 | |
| 296 | WSASetLastError(WSAEINVAL); |
| 297 | return -1; |
| 298 | } |
| 299 | |
| 300 | // Note: get_errno() is provided by fl/stl/cerrno.h |
| 301 | // Note: Platform abstraction functions (create_platform_socket, etc.) are not needed |
no outgoing calls
no test coverage detected