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

Function runtime_accept_connection

src/daemon/runtime.c:1982–2032  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1980}
1981
1982static void runtime_accept_connection(cbm_daemon_runtime_service_t *service,
1983 cbm_daemon_ipc_connection_t *connection) {
1984 uint64_t peer_pid = cbm_daemon_ipc_connection_peer_pid(connection);
1985 if (peer_pid == 0) {
1986 cbm_daemon_ipc_connection_close(connection);
1987 return;
1988 }
1989
1990 cbm_mutex_lock(&service->mutex);
1991 bool running = service->state == CBM_DAEMON_RUNTIME_SERVICE_RUNNING;
1992 bool capacity = service->active_connections >= service->worker_capacity;
1993 cbm_daemon_runtime_worker_t *worker =
1994 running && !capacity ? runtime_find_free_worker_locked(service) : NULL;
1995 if (worker) {
1996 worker->connection = connection;
1997 worker->peer_process_id = peer_pid;
1998 worker->client_id = CBM_DAEMON_CLIENT_ID_INVALID;
1999 worker->admitted = false;
2000 worker->admission_committed = false;
2001 worker->final_response_inflight = false;
2002 worker->application_session = NULL;
2003 worker->application_session_opened = false;
2004 worker->application_cancelled = false;
2005 worker->application_thread_started = false;
2006 free(worker->application_request);
2007 worker->application_request = NULL;
2008 worker->application_request_length = 0;
2009 worker->joining = false;
2010 worker->in_use = true;
2011 atomic_store_explicit(&worker->done, false, memory_order_release);
2012 atomic_store_explicit(&worker->disconnecting, false, memory_order_release);
2013 atomic_store_explicit(&worker->application_thread_done, false, memory_order_release);
2014 service->active_connections++;
2015 int created = cbm_thread_create(&worker->thread, RUNTIME_WORKER_STACK_SIZE,
2016 runtime_connection_worker, worker);
2017 if (created == 0) {
2018 worker->thread_started = true;
2019 cbm_mutex_unlock(&service->mutex);
2020 return;
2021 }
2022 service->active_connections--;
2023 runtime_worker_reset_after_join(worker);
2024 }
2025 cbm_mutex_unlock(&service->mutex);
2026
2027 if (!running) {
2028 runtime_reject_inline(connection, "CBM daemon is stopping");
2029 } else {
2030 runtime_reject_inline(connection, "CBM daemon connection capacity reached");
2031 }
2032}
2033
2034static bool runtime_service_can_exit(cbm_daemon_runtime_service_t *service, uint64_t now_ms) {
2035 bool can_exit = false;

Callers 1

runtime_accept_loopFunction · 0.85

Calls 8

cbm_mutex_lockFunction · 0.85
cbm_thread_createFunction · 0.85
cbm_mutex_unlockFunction · 0.85
runtime_reject_inlineFunction · 0.85

Tested by

no test coverage detected