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

Function runtime_accept_connection

src/daemon/runtime.c:2333–2383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2331}
2332
2333static void runtime_accept_connection(cbm_daemon_runtime_service_t *service,
2334 cbm_daemon_ipc_connection_t *connection) {
2335 uint64_t peer_pid = cbm_daemon_ipc_connection_peer_pid(connection);
2336 if (peer_pid == 0) {
2337 cbm_daemon_ipc_connection_close(connection);
2338 return;
2339 }
2340
2341 cbm_mutex_lock(&service->mutex);
2342 bool running = service->state == CBM_DAEMON_RUNTIME_SERVICE_RUNNING;
2343 bool capacity = service->active_connections >= service->worker_capacity;
2344 cbm_daemon_runtime_worker_t *worker =
2345 running && !capacity ? runtime_find_free_worker_locked(service) : NULL;
2346 if (worker) {
2347 worker->connection = connection;
2348 worker->peer_process_id = peer_pid;
2349 worker->client_id = CBM_DAEMON_CLIENT_ID_INVALID;
2350 worker->admitted = false;
2351 worker->admission_committed = false;
2352 worker->final_response_inflight = false;
2353 worker->application_session = NULL;
2354 worker->application_session_opened = false;
2355 worker->application_cancelled = false;
2356 worker->application_thread_started = false;
2357 free(worker->application_request);
2358 worker->application_request = NULL;
2359 worker->application_request_length = 0;
2360 worker->joining = false;
2361 worker->in_use = true;
2362 atomic_store_explicit(&worker->done, false, memory_order_release);
2363 atomic_store_explicit(&worker->disconnecting, false, memory_order_release);
2364 atomic_store_explicit(&worker->application_thread_done, false, memory_order_release);
2365 service->active_connections++;
2366 int created = cbm_thread_create(&worker->thread, RUNTIME_WORKER_STACK_SIZE,
2367 runtime_connection_worker, worker);
2368 if (created == 0) {
2369 worker->thread_started = true;
2370 cbm_mutex_unlock(&service->mutex);
2371 return;
2372 }
2373 service->active_connections--;
2374 runtime_worker_reset_after_join(worker);
2375 }
2376 cbm_mutex_unlock(&service->mutex);
2377
2378 if (!running) {
2379 runtime_reject_inline(connection, "CBM daemon is stopping");
2380 } else {
2381 runtime_reject_inline(connection, "CBM daemon connection capacity reached");
2382 }
2383}
2384
2385static bool runtime_service_can_exit(cbm_daemon_runtime_service_t *service, uint64_t now_ms) {
2386 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