MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_httpd_accept

Function cbm_httpd_accept

src/ui/httpd.c:355–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

353/* ── Accept ───────────────────────────────────────────────────── */
354
355cbm_http_conn_t *cbm_httpd_accept(cbm_httpd_t *d, int timeout_ms) {
356 if (!d)
357 return NULL;
358 cbm_mutex_lock(&d->active_mutex);
359 bool interrupted = d->interrupted;
360 int send_buffer = d->send_buffer_for_test;
361 cbm_mutex_unlock(&d->active_mutex);
362 if (interrupted)
363 return NULL;
364 if (wait_readable(d->fd, timeout_ms) != 1)
365 return NULL;
366
367 cbm_sock_t cfd = accept(d->fd, NULL, NULL);
368 if (cfd == CBM_SOCK_BAD)
369 return NULL;
370
371 int one = 1;
372 setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, sizeof(one));
373 /* An explicit SO_SNDBUF also disables Windows dynamic send buffering,
374 * which otherwise grows kernel-side queuing past any fixed payload and
375 * removes the backpressure point the deadline/interrupt tests rely on. */
376 if (send_buffer > 0)
377 setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, (const char *)&send_buffer, sizeof(send_buffer));
378#ifdef SO_NOSIGPIPE
379 setsockopt(cfd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one));
380#endif
381
382 if (!socket_set_nonblocking(cfd)) {
383 cbm_sock_close(cfd);
384 return NULL;
385 }
386
387 cbm_http_conn_t *c = calloc(1, sizeof(*c));
388 if (!c) {
389 cbm_sock_close(cfd);
390 return NULL;
391 }
392 c->fd = cfd;
393 c->owner = d;
394 c->send_deadline_ms =
395 d->send_deadline_for_test_ms > 0 ? d->send_deadline_for_test_ms : CBM_HTTP_SEND_DEADLINE_MS;
396 atomic_init(&c->response_started, false);
397
398 cbm_mutex_lock(&d->active_mutex);
399 if (d->interrupted || d->active) {
400 cbm_mutex_unlock(&d->active_mutex);
401 cbm_sock_close(cfd);
402 free(c);
403 return NULL;
404 }
405 c->recv_deadline_ms = d->recv_deadline_ms;
406 d->active = c;
407 cbm_mutex_unlock(&d->active_mutex);
408 return c;
409}
410
411void cbm_httpd_conn_close(cbm_http_conn_t *c) {
412 if (!c)

Callers 3

cbm_http_server_runFunction · 0.85
test_httpd.cFile · 0.85
th_httpd_large_replyFunction · 0.85

Calls 5

cbm_mutex_lockFunction · 0.85
cbm_mutex_unlockFunction · 0.85
wait_readableFunction · 0.85
socket_set_nonblockingFunction · 0.85
acceptFunction · 0.50

Tested by 1

th_httpd_large_replyFunction · 0.68