| 185 | /* ── Accept ───────────────────────────────────────────────────── */ |
| 186 | |
| 187 | cbm_http_conn_t *cbm_httpd_accept(cbm_httpd_t *d, int timeout_ms) { |
| 188 | if (!d) |
| 189 | return NULL; |
| 190 | if (wait_readable(d->fd, timeout_ms) != 1) |
| 191 | return NULL; |
| 192 | |
| 193 | cbm_sock_t cfd = accept(d->fd, NULL, NULL); |
| 194 | if (cfd == CBM_SOCK_BAD) |
| 195 | return NULL; |
| 196 | |
| 197 | int one = 1; |
| 198 | setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, sizeof(one)); |
| 199 | #ifdef SO_NOSIGPIPE |
| 200 | setsockopt(cfd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one)); |
| 201 | #endif |
| 202 | |
| 203 | cbm_http_conn_t *c = calloc(1, sizeof(*c)); |
| 204 | if (!c) { |
| 205 | cbm_sock_close(cfd); |
| 206 | return NULL; |
| 207 | } |
| 208 | c->fd = cfd; |
| 209 | c->recv_deadline_ms = d->recv_deadline_ms; |
| 210 | return c; |
| 211 | } |
| 212 | |
| 213 | void cbm_httpd_conn_close(cbm_http_conn_t *c) { |
| 214 | if (!c) |
no test coverage detected