Read until the server closes the connection (Connection: close model). */
| 102 | |
| 103 | /* Read until the server closes the connection (Connection: close model). */ |
| 104 | static int th_recv_until_close(th_sock_t s, char *buf, size_t bufsz) { |
| 105 | size_t off = 0; |
| 106 | for (;;) { |
| 107 | #ifdef _WIN32 |
| 108 | int n = recv(s, buf + off, (int)(bufsz - 1 - off), 0); |
| 109 | #else |
| 110 | ssize_t n = recv(s, buf + off, bufsz - 1 - off, 0); |
| 111 | #endif |
| 112 | if (n <= 0) |
| 113 | break; |
| 114 | off += (size_t)n; |
| 115 | if (off >= bufsz - 1) |
| 116 | break; |
| 117 | } |
| 118 | buf[off] = '\0'; |
| 119 | return (int)off; |
| 120 | } |
| 121 | |
| 122 | /* One-shot HTTP exchange. Returns response length, 0 on connect failure. */ |
| 123 | static int th_http(int port, const char *request, char *resp, size_t respsz) { |
no outgoing calls
no test coverage detected