| 372 | } |
| 373 | |
| 374 | static void * |
| 375 | client_handler(void *sock_id) |
| 376 | { |
| 377 | int s = (int)(uintptr_t)sock_id; |
| 378 | char buffer[1024]; |
| 379 | char info_str[1024]; |
| 380 | snprintf(info_str, sizeof(info_str), |
| 381 | "{\"version\":\"%s\",\"pid\":%d,\"max_output_len\":%d}", |
| 382 | telemetry_version, getpid(), MAX_OUTPUT_LEN); |
| 383 | if (write(s, info_str, strlen(info_str)) < 0) { |
| 384 | TMTY_LOG(DEBUG, "Socket write base info to client failed\n"); |
| 385 | goto exit; |
| 386 | } |
| 387 | |
| 388 | /* receive data is not null terminated */ |
| 389 | int bytes = read(s, buffer, sizeof(buffer) - 1); |
| 390 | while (bytes > 0) { |
| 391 | buffer[bytes] = 0; |
| 392 | const char *cmd = strtok(buffer, ","); |
| 393 | const char *param = strtok(NULL, "\0"); |
| 394 | telemetry_cb fn = unknown_command; |
| 395 | int i; |
| 396 | |
| 397 | if (cmd && strlen(cmd) < MAX_CMD_LEN) { |
| 398 | rte_spinlock_lock(&callback_sl); |
| 399 | for (i = 0; i < num_callbacks; i++) |
| 400 | if (strcmp(cmd, callbacks[i].cmd) == 0) { |
| 401 | fn = callbacks[i].fn; |
| 402 | break; |
| 403 | } |
| 404 | rte_spinlock_unlock(&callback_sl); |
| 405 | } |
| 406 | perform_command(fn, cmd, param, s); |
| 407 | |
| 408 | bytes = read(s, buffer, sizeof(buffer) - 1); |
| 409 | } |
| 410 | exit: |
| 411 | close(s); |
| 412 | rte_atomic_fetch_sub_explicit(&v2_clients, 1, rte_memory_order_relaxed); |
| 413 | return NULL; |
| 414 | } |
| 415 | |
| 416 | static void * |
| 417 | socket_listener(void *socket) |
nothing calls this directly
no test coverage detected