Wait until the socket is readable. 1 = readable, 0 = timeout, -1 = error. * Windows uses select() deliberately (WSAPoll has a Won't-Fix bug where * certain socket errors are never reported, which can stall an event loop). */
| 72 | * Windows uses select() deliberately (WSAPoll has a Won't-Fix bug where |
| 73 | * certain socket errors are never reported, which can stall an event loop). */ |
| 74 | static int wait_readable(cbm_sock_t fd, int timeout_ms) { |
| 75 | #ifdef _WIN32 |
| 76 | fd_set rfds; |
| 77 | FD_ZERO(&rfds); |
| 78 | FD_SET(fd, &rfds); |
| 79 | struct timeval tv; |
| 80 | tv.tv_sec = timeout_ms / 1000; |
| 81 | tv.tv_usec = (timeout_ms % 1000) * 1000; |
| 82 | int rc = select(0, &rfds, NULL, NULL, &tv); |
| 83 | return rc < 0 ? -1 : (rc > 0 ? 1 : 0); |
| 84 | #else |
| 85 | struct pollfd pfd; |
| 86 | pfd.fd = fd; |
| 87 | pfd.events = POLLIN; |
| 88 | pfd.revents = 0; |
| 89 | int rc = poll(&pfd, 1, timeout_ms); |
| 90 | if (rc < 0) |
| 91 | return errno == EINTR ? 0 : -1; |
| 92 | return rc > 0 ? 1 : 0; |
| 93 | #endif |
| 94 | } |
| 95 | |
| 96 | static int send_all(cbm_sock_t fd, const void *data, size_t len) { |
| 97 | const char *p = data; |
no outgoing calls
no test coverage detected