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

Function runtime_accept_connection

src/daemon/runtime.c:1954–2004  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1952}
1953
1954static void runtime_accept_connection(cbm_daemon_runtime_service_t *service,
1955 cbm_daemon_ipc_connection_t *connection) {
1956 uint64_t peer_pid = cbm_daemon_ipc_connection_peer_pid(connection);
1957 if (peer_pid == 0) {
1958 cbm_daemon_ipc_connection_close(connection);
1959 return;
1960 }
1961
1962 cbm_mutex_lock(&service->mutex);
1963 bool running = service->state == CBM_DAEMON_RUNTIME_SERVICE_RUNNING;
1964 bool capacity = service->active_connections >= service->worker_capacity;
1965 cbm_daemon_runtime_worker_t *worker =
1966 running && !capacity ? runtime_find_free_worker_locked(service) : NULL;
1967 if (worker) {
1968 worker->connection = connection;
1969 worker->peer_process_id = peer_pid;
1970 worker->client_id = CBM_DAEMON_CLIENT_ID_INVALID;
1971 worker->admitted = false;
1972 worker->admission_committed = false;
1973 worker->final_response_inflight = false;
1974 worker->application_session = NULL;
1975 worker->application_session_opened = false;
1976 worker->application_cancelled = false;
1977 worker->application_thread_started = false;
1978 free(worker->application_request);
1979 worker->application_request = NULL;
1980 worker->application_request_length = 0;
1981 worker->joining = false;
1982 worker->in_use = true;
1983 atomic_store_explicit(&worker->done, false, memory_order_release);
1984 atomic_store_explicit(&worker->disconnecting, false, memory_order_release);
1985 atomic_store_explicit(&worker->application_thread_done, false, memory_order_release);
1986 service->active_connections++;
1987 int created = cbm_thread_create(&worker->thread, RUNTIME_WORKER_STACK_SIZE,
1988 runtime_connection_worker, worker);
1989 if (created == 0) {
1990 worker->thread_started = true;
1991 cbm_mutex_unlock(&service->mutex);
1992 return;
1993 }
1994 service->active_connections--;
1995 runtime_worker_reset_after_join(worker);
1996 }
1997 cbm_mutex_unlock(&service->mutex);
1998
1999 if (!running) {
2000 runtime_reject_inline(connection, "CBM daemon is stopping");
2001 } else {
2002 runtime_reject_inline(connection, "CBM daemon connection capacity reached");
2003 }
2004}
2005
2006static bool runtime_service_can_exit(cbm_daemon_runtime_service_t *service, uint64_t now_ms) {
2007 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