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

Function cbm_httpd_accept

src/ui/httpd.c:350–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

cbm_http_server_runFunction · 0.85
test_httpd.cFile · 0.85
th_httpd_large_replyFunction · 0.85

Calls 4

cbm_mutex_lockFunction · 0.85
cbm_mutex_unlockFunction · 0.85
wait_readableFunction · 0.85
socket_set_nonblockingFunction · 0.85

Tested by 1

th_httpd_large_replyFunction · 0.68