Wait against the caller's absolute deadline. Windows uses short select() * slices because shutdown() from the stop thread does not reliably wake a * Winsock select(); POSIX keeps its one-shot poll wait and shutdown fast path. * 1 = ready, 0 = original deadline expired, -1 = interrupted/error. */
| 164 | * Winsock select(); POSIX keeps its one-shot poll wait and shutdown fast path. |
| 165 | * 1 = ready, 0 = original deadline expired, -1 = interrupted/error. */ |
| 166 | static int wait_connection_ready(cbm_http_conn_t *connection, bool writing, int64_t deadline) { |
| 167 | for (;;) { |
| 168 | if (connection_interrupted(connection)) |
| 169 | return -1; |
| 170 | |
| 171 | int64_t remaining = deadline - now_ms(); |
| 172 | if (remaining <= 0) |
| 173 | return 0; |
| 174 | int timeout_ms = remaining > INT_MAX ? INT_MAX : (int)remaining; |
| 175 | #ifdef _WIN32 |
| 176 | if (timeout_ms > CBM_HTTP_WAIT_SLICE_MS) |
| 177 | timeout_ms = CBM_HTTP_WAIT_SLICE_MS; |
| 178 | #endif |
| 179 | |
| 180 | int ready = wait_ready(connection->fd, writing, timeout_ms); |
| 181 | if (connection_interrupted(connection)) |
| 182 | return -1; |
| 183 | if (ready != 0) |
| 184 | return ready; |
| 185 | /* A Windows slice or POSIX EINTR is not the caller's timeout. */ |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static int send_all(cbm_http_conn_t *connection, const void *data, size_t len, int64_t deadline) { |
| 190 | const char *p = data; |
no test coverage detected