MCPcopy Create free account
hub / github.com/F-Stack/f-stack / client_handler

Function client_handler

dpdk/lib/telemetry/telemetry.c:374–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372}
373
374static void *
375client_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 }
410exit:
411 close(s);
412 rte_atomic_fetch_sub_explicit(&v2_clients, 1, rte_memory_order_relaxed);
413 return NULL;
414}
415
416static void *
417socket_listener(void *socket)

Callers

nothing calls this directly

Calls 9

snprintfFunction · 0.85
strtokFunction · 0.85
strcmpFunction · 0.85
perform_commandFunction · 0.70
writeFunction · 0.50
readFunction · 0.50
rte_spinlock_lockFunction · 0.50
rte_spinlock_unlockFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected