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

Function runtime_connection_worker

src/daemon/runtime.c:2033–2258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2031}
2032
2033static void *runtime_connection_worker(void *opaque) {
2034 cbm_daemon_runtime_worker_t *worker = opaque;
2035 cbm_daemon_runtime_service_t *service = worker->service;
2036 cbm_daemon_frame_t frame = {0};
2037 uint8_t *payload = NULL;
2038 char requested_version[CBM_DAEMON_VERSION_TEXT_SIZE];
2039 char requested_build[CBM_DAEMON_BUILD_FINGERPRINT_SIZE];
2040
2041 int received = cbm_daemon_ipc_receive_frame_bounded(
2042 worker->connection, runtime_first_frame_timeout_ms(service),
2043 CBM_DAEMON_ACTIVATION_SHUTDOWN_REQUEST_SIZE, &frame, &payload);
2044 if (received != 1 || frame.type != CBM_DAEMON_FRAME_REQUEST) {
2045 free(payload);
2046 runtime_worker_finish(worker);
2047 return NULL;
2048 }
2049 if (frame.flags == CBM_DAEMON_RUNTIME_OP_ACTIVATION_SHUTDOWN) {
2050 runtime_worker_handle_activation_shutdown(worker, payload, frame.length);
2051 free(payload);
2052 return NULL;
2053 }
2054 if (frame.flags == CBM_DAEMON_RUNTIME_OP_STATUS) {
2055 runtime_worker_handle_status(worker, payload, frame.length);
2056 free(payload);
2057 return NULL;
2058 }
2059 if (frame.flags == CBM_DAEMON_RUNTIME_OP_STOP) {
2060 runtime_worker_handle_stop(worker, payload, frame.length);
2061 free(payload);
2062 return NULL;
2063 }
2064 if (frame.flags != CBM_DAEMON_RUNTIME_OP_HELLO ||
2065 frame.length != CBM_DAEMON_RENDEZVOUS_REQUEST_SIZE ||
2066 !runtime_rendezvous_request_decode(payload, requested_version, requested_build)) {
2067 free(payload);
2068 runtime_worker_finish(worker);
2069 return NULL;
2070 }
2071 free(payload);
2072 payload = NULL;
2073
2074 cbm_daemon_runtime_connect_result_t hello_result;
2075 memset(&hello_result, 0, sizeof(hello_result));
2076 cbm_daemon_hello_status_t hello_status = runtime_rendezvous_compare(
2077 service->identity.semantic_version, service->identity.build_fingerprint, requested_version,
2078 requested_build, &hello_result.conflict);
2079 if (hello_status != CBM_DAEMON_HELLO_COMPATIBLE) {
2080 if (hello_status == CBM_DAEMON_HELLO_INVALID) {
2081 runtime_worker_finish(worker);
2082 return NULL;
2083 }
2084 hello_result.status = CBM_DAEMON_RUNTIME_CONNECT_CONFLICT;
2085 hello_result.hello_status = hello_status;
2086 (void)cbm_daemon_conflict_format(&hello_result.conflict, hello_result.message,
2087 sizeof(hello_result.message));
2088 if (!cbm_daemon_conflict_log_append(service->conflict_log_path, &hello_result.conflict,
2089 service->conflict_log_cap_bytes)) {
2090 /* This goes through the daemon operation-log sink, never back

Callers

nothing calls this directly

Tested by

no test coverage detected