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

Function create_socket

dpdk/lib/telemetry/telemetry.c:472–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470}
471
472static int
473create_socket(char *path)
474{
475 int sock = socket(AF_UNIX, SOCK_SEQPACKET, 0);
476 if (sock < 0) {
477 TMTY_LOG(ERR, "Error with socket creation, %s\n", strerror(errno));
478 return -1;
479 }
480
481 struct sockaddr_un sun = {.sun_family = AF_UNIX};
482 strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
483 TMTY_LOG(DEBUG, "Attempting socket bind to path '%s'\n", path);
484
485 if (bind(sock, (void *) &sun, sizeof(sun)) < 0) {
486 struct stat st;
487
488 TMTY_LOG(DEBUG, "Initial bind to socket '%s' failed.\n", path);
489
490 /* first check if we have a runtime dir */
491 if (stat(socket_dir, &st) < 0 || !S_ISDIR(st.st_mode)) {
492 TMTY_LOG(ERR, "Cannot access DPDK runtime directory: %s\n", socket_dir);
493 close(sock);
494 return -ENOENT;
495 }
496
497 /* check if current socket is active */
498 if (connect(sock, (void *)&sun, sizeof(sun)) == 0) {
499 close(sock);
500 return -EADDRINUSE;
501 }
502
503 /* socket is not active, delete and attempt rebind */
504 TMTY_LOG(DEBUG, "Attempting unlink and retrying bind\n");
505 unlink(sun.sun_path);
506 if (bind(sock, (void *) &sun, sizeof(sun)) < 0) {
507 TMTY_LOG(ERR, "Error binding socket: %s\n", strerror(errno));
508 close(sock);
509 return -errno; /* if unlink failed, this will be -EADDRINUSE as above */
510 }
511 }
512
513 if (listen(sock, 1) < 0) {
514 TMTY_LOG(ERR, "Error calling listen for socket: %s\n", strerror(errno));
515 unlink(sun.sun_path);
516 close(sock);
517 return -errno;
518 }
519 TMTY_LOG(DEBUG, "Socket creation and binding ok\n");
520
521 return sock;
522}
523
524static void
525set_thread_name(pthread_t id __rte_unused, const char *name __rte_unused)

Callers 2

telemetry_legacy_initFunction · 0.85
telemetry_v2_initFunction · 0.85

Calls 7

socketClass · 0.70
statClass · 0.70
strlcpyFunction · 0.50
bindFunction · 0.50
closeFunction · 0.50
connectFunction · 0.50
listenFunction · 0.50

Tested by

no test coverage detected