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

Function runtime_accept_connection

src/daemon/runtime.c:2013–2063  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2011}
2012
2013static void runtime_accept_connection(cbm_daemon_runtime_service_t *service,
2014 cbm_daemon_ipc_connection_t *connection) {
2015 uint64_t peer_pid = cbm_daemon_ipc_connection_peer_pid(connection);
2016 if (peer_pid == 0) {
2017 cbm_daemon_ipc_connection_close(connection);
2018 return;
2019 }
2020
2021 cbm_mutex_lock(&service->mutex);
2022 bool running = service->state == CBM_DAEMON_RUNTIME_SERVICE_RUNNING;
2023 bool capacity = service->active_connections >= service->worker_capacity;
2024 cbm_daemon_runtime_worker_t *worker =
2025 running && !capacity ? runtime_find_free_worker_locked(service) : NULL;
2026 if (worker) {
2027 worker->connection = connection;
2028 worker->peer_process_id = peer_pid;
2029 worker->client_id = CBM_DAEMON_CLIENT_ID_INVALID;
2030 worker->admitted = false;
2031 worker->admission_committed = false;
2032 worker->final_response_inflight = false;
2033 worker->application_session = NULL;
2034 worker->application_session_opened = false;
2035 worker->application_cancelled = false;
2036 worker->application_thread_started = false;
2037 free(worker->application_request);
2038 worker->application_request = NULL;
2039 worker->application_request_length = 0;
2040 worker->joining = false;
2041 worker->in_use = true;
2042 atomic_store_explicit(&worker->done, false, memory_order_release);
2043 atomic_store_explicit(&worker->disconnecting, false, memory_order_release);
2044 atomic_store_explicit(&worker->application_thread_done, false, memory_order_release);
2045 service->active_connections++;
2046 int created = cbm_thread_create(&worker->thread, RUNTIME_WORKER_STACK_SIZE,
2047 runtime_connection_worker, worker);
2048 if (created == 0) {
2049 worker->thread_started = true;
2050 cbm_mutex_unlock(&service->mutex);
2051 return;
2052 }
2053 service->active_connections--;
2054 runtime_worker_reset_after_join(worker);
2055 }
2056 cbm_mutex_unlock(&service->mutex);
2057
2058 if (!running) {
2059 runtime_reject_inline(connection, "CBM daemon is stopping");
2060 } else {
2061 runtime_reject_inline(connection, "CBM daemon connection capacity reached");
2062 }
2063}
2064
2065static bool runtime_service_can_exit(cbm_daemon_runtime_service_t *service, uint64_t now_ms) {
2066 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