| 391 | } |
| 392 | |
| 393 | cbm_daemon_client_id_t cbm_daemon_client_connected(cbm_daemon_coordinator_t *coordinator, |
| 394 | uint64_t now_ms) { |
| 395 | if (!coordinator) { |
| 396 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 397 | } |
| 398 | |
| 399 | cbm_daemon_client_t *client = malloc(sizeof(*client)); |
| 400 | if (!client) { |
| 401 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 402 | } |
| 403 | |
| 404 | cbm_mutex_lock(&coordinator->mutex); |
| 405 | if (coordinator->state != CBM_DAEMON_COORDINATOR_RUNNING) { |
| 406 | cbm_mutex_unlock(&coordinator->mutex); |
| 407 | free(client); |
| 408 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 409 | } |
| 410 | cbm_daemon_client_id_t client_id = issue_client_id_locked(coordinator); |
| 411 | if (client_id == CBM_DAEMON_CLIENT_ID_INVALID) { |
| 412 | cbm_mutex_unlock(&coordinator->mutex); |
| 413 | free(client); |
| 414 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 415 | } |
| 416 | client->id = client_id; |
| 417 | client->last_heartbeat_ms = now_ms; |
| 418 | client->next = coordinator->clients; |
| 419 | coordinator->clients = client; |
| 420 | coordinator->client_count++; |
| 421 | cbm_mutex_unlock(&coordinator->mutex); |
| 422 | return client_id; |
| 423 | } |
| 424 | |
| 425 | bool cbm_daemon_client_disconnected(cbm_daemon_coordinator_t *coordinator, |
| 426 | cbm_daemon_client_id_t client_id, uint64_t now_ms) { |
no test coverage detected