Like th_http but arms a client-side receive-timeout watchdog. If the * single-threaded server wedges, recv() returns instead of blocking forever, so * the test FAILs deterministically rather than hanging CI. 0 on connect/timeout. */
| 3370 | * single-threaded server wedges, recv() returns instead of blocking forever, so |
| 3371 | * the test FAILs deterministically rather than hanging CI. 0 on connect/timeout. */ |
| 3372 | static int th_http_deadline(int port, const char *request, char *resp, size_t respsz, |
| 3373 | int timeout_ms) { |
| 3374 | char *prepared = th_request_with_ui_headers(port, request); |
| 3375 | if (!prepared) |
| 3376 | return 0; |
| 3377 | th_sock_t s = th_connect(port); |
| 3378 | if (s == TH_SOCK_BAD) { |
| 3379 | free(prepared); |
| 3380 | return 0; |
| 3381 | } |
| 3382 | #ifdef _WIN32 |
| 3383 | DWORD tv = (DWORD)timeout_ms; |
| 3384 | setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv)); |
| 3385 | #else |
| 3386 | struct timeval tv; |
| 3387 | tv.tv_sec = timeout_ms / 1000; |
| 3388 | tv.tv_usec = (timeout_ms % 1000) * 1000; |
| 3389 | setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); |
| 3390 | #endif |
| 3391 | if (th_send_all(s, prepared, strlen(prepared)) != 0) { |
| 3392 | free(prepared); |
| 3393 | th_sock_close(s); |
| 3394 | return 0; |
| 3395 | } |
| 3396 | free(prepared); |
| 3397 | int n = th_recv_until_close(s, resp, respsz); |
| 3398 | th_sock_close(s); |
| 3399 | return n; |
| 3400 | } |
| 3401 | |
| 3402 | /* #798 was a single-threaded-server wedge: list_projects never returned and the |
| 3403 | * whole UI stopped answering. Assert the running server answers list_projects |
no test coverage detected