#include <string.h>
#include <sys/file.h>
#include <sys/time.h>
-#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <rte_errno.h>
#include <rte_lcore.h>
#include <rte_log.h>
-#include <rte_tailq.h>
#include "eal_memcfg.h"
#include "eal_private.h"
#include "eal_internal_cfg.h"
static int mp_fd = -1;
+static pthread_t mp_handle_tid;
static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */
static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */
static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER;
msgh.msg_control = control;
msgh.msg_controllen = sizeof(control);
+retry:
msglen = recvmsg(mp_fd, &msgh, 0);
+
+ /* zero length message means socket was closed */
+ if (msglen == 0)
+ return 0;
+
if (msglen < 0) {
+ if (errno == EINTR)
+ goto retry;
+
RTE_LOG(ERR, EAL, "recvmsg failed, %s\n", strerror(errno));
return -1;
}
RTE_LOG(ERR, EAL, "invalid received data length\n");
return -1;
}
- return 0;
+ return msglen;
}
static void
struct mp_msg_internal msg;
struct sockaddr_un sa;
- while (1) {
- if (read_msg(&msg, &sa) == 0)
- process_msg(&msg, &sa);
+ while (mp_fd >= 0) {
+ int ret;
+
+ ret = read_msg(&msg, &sa);
+ if (ret <= 0)
+ break;
+
+ process_msg(&msg, &sa);
}
return NULL;
}
static void
-close_socket_fd(void)
+close_socket_fd(int fd)
{
char path[PATH_MAX];
- if (mp_fd < 0)
- return;
-
- close(mp_fd);
+ close(fd);
create_socket_path(peer_name, path, sizeof(path));
unlink(path);
}
{
char path[PATH_MAX];
int dir_fd;
- pthread_t mp_handle_tid;
const struct internal_config *internal_conf =
eal_get_internal_configuration();
void
rte_mp_channel_cleanup(void)
{
- close_socket_fd();
+ int fd;
+
+ if (mp_fd < 0)
+ return;
+
+ fd = mp_fd;
+ mp_fd = -1;
+ pthread_cancel(mp_handle_tid);
+ pthread_join(mp_handle_tid, NULL);
+ close_socket_fd(fd);
}
/**