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

Function send_msg

dpdk/lib/eal/common/eal_common_proc.c:685–741  ·  view source on GitHub ↗

* Return -1, as fail to send message and it's caused by the local side. * Return 0, as fail to send message and it's caused by the remote side. * Return 1, as succeed to send message. */

Source from the content-addressed store, hash-verified

683 * Return 1, as succeed to send message.
684 */
685static int
686send_msg(const char *dst_path, struct rte_mp_msg *msg, int type)
687{
688 int snd;
689 struct iovec iov;
690 struct msghdr msgh;
691 struct cmsghdr *cmsg;
692 struct sockaddr_un dst;
693 struct mp_msg_internal m;
694 int fd_size = msg->num_fds * sizeof(int);
695 char control[CMSG_SPACE(fd_size)];
696
697 m.type = type;
698 memcpy(&m.msg, msg, sizeof(*msg));
699
700 memset(&dst, 0, sizeof(dst));
701 dst.sun_family = AF_UNIX;
702 strlcpy(dst.sun_path, dst_path, sizeof(dst.sun_path));
703
704 memset(&msgh, 0, sizeof(msgh));
705 memset(control, 0, sizeof(control));
706
707 iov.iov_base = &m;
708 iov.iov_len = sizeof(m) - sizeof(msg->fds);
709
710 msgh.msg_name = &dst;
711 msgh.msg_namelen = sizeof(dst);
712 msgh.msg_iov = &iov;
713 msgh.msg_iovlen = 1;
714 msgh.msg_control = control;
715 msgh.msg_controllen = sizeof(control);
716
717 cmsg = CMSG_FIRSTHDR(&msgh);
718 cmsg->cmsg_len = CMSG_LEN(fd_size);
719 cmsg->cmsg_level = SOL_SOCKET;
720 cmsg->cmsg_type = SCM_RIGHTS;
721 memcpy(CMSG_DATA(cmsg), msg->fds, fd_size);
722
723 do {
724 snd = sendmsg(mp_fd, &msgh, 0);
725 } while (snd < 0 && errno == EINTR);
726
727 if (snd < 0) {
728 rte_errno = errno;
729 /* Check if it caused by peer process exits */
730 if (errno == ECONNREFUSED &&
731 rte_eal_process_type() == RTE_PROC_PRIMARY) {
732 unlink(dst_path);
733 return 0;
734 }
735 RTE_LOG(ERR, EAL, "failed to send to (%s) due to %s\n",
736 dst_path, strerror(errno));
737 return -1;
738 }
739
740 return 1;
741}
742

Callers 3

mp_sendFunction · 0.70
mp_request_asyncFunction · 0.70
mp_request_syncFunction · 0.70

Calls 5

memsetFunction · 0.85
sendmsgFunction · 0.85
rte_eal_process_typeFunction · 0.85
memcpyFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected