| 2408 | } |
| 2409 | |
| 2410 | static void *runtime_accept_loop(void *opaque) { |
| 2411 | cbm_daemon_runtime_service_t *service = opaque; |
| 2412 | for (;;) { |
| 2413 | runtime_reap_completed_workers(service); |
| 2414 | cbm_mutex_lock(&service->mutex); |
| 2415 | cbm_daemon_runtime_service_state_t state = service->state; |
| 2416 | cbm_mutex_unlock(&service->mutex); |
| 2417 | if (state == CBM_DAEMON_RUNTIME_SERVICE_EXITED) { |
| 2418 | break; |
| 2419 | } |
| 2420 | if (state == CBM_DAEMON_RUNTIME_SERVICE_STOPPING) { |
| 2421 | runtime_service_interrupt_connections(service); |
| 2422 | if (runtime_service_can_exit(service, cbm_now_ms())) { |
| 2423 | break; |
| 2424 | } |
| 2425 | uint64_t tick_deadline = runtime_deadline_after(1); |
| 2426 | runtime_wait_tick(tick_deadline); |
| 2427 | continue; |
| 2428 | } |
| 2429 | |
| 2430 | /* Self-retire a generation lingering for a cold-storm peer once the peer |
| 2431 | * drains or the bounded window elapses, without an external driver. A |
| 2432 | * no-op unless a last-committed-client linger is armed. */ |
| 2433 | cbm_daemon_runtime_service_reconcile_lifetime(service); |
| 2434 | |
| 2435 | cbm_daemon_ipc_connection_t *connection = NULL; |
| 2436 | int accepted = |
| 2437 | cbm_daemon_ipc_accept(service->listener, RUNTIME_ACCEPT_POLL_MS, &connection); |
| 2438 | if (accepted == 1 && connection) { |
| 2439 | runtime_accept_connection(service, connection); |
| 2440 | } else if (accepted < 0) { |
| 2441 | /* IPC intentionally combines invalid-peer and listener errors. |
| 2442 | * Retry while RUNNING so one hostile peer cannot stop the daemon. */ |
| 2443 | uint64_t tick_deadline = runtime_deadline_after(1); |
| 2444 | runtime_wait_tick(tick_deadline); |
| 2445 | } |
| 2446 | } |
| 2447 | runtime_reap_completed_workers(service); |
| 2448 | atomic_store_explicit(&service->accept_thread_done, true, memory_order_release); |
| 2449 | return NULL; |
| 2450 | } |
| 2451 | |
| 2452 | static char *runtime_string_copy_bounded(const char *value, size_t capacity) { |
| 2453 | size_t length = 0; |
nothing calls this directly
no test coverage detected