X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fsessiond-comm%2Finet.c;h=f55482e422f173dd28921201b2815651299ad205;hp=e8d3afef316696ebdef315e92e58870f5c784c52;hb=90e535ef0d0433d31e805775f85e4d187b1cf82c;hpb=32dd26fbc3c69fe677a7917535e10ace066e674c diff --git a/src/common/sessiond-comm/inet.c b/src/common/sessiond-comm/inet.c index e8d3afef3..f55482e42 100644 --- a/src/common/sessiond-comm/inet.c +++ b/src/common/sessiond-comm/inet.c @@ -26,8 +26,7 @@ #include #include -#include -#include +#include #include "inet.h" @@ -47,7 +46,7 @@ static const struct lttcomm_proto_ops inet_ops = { /* * Creates an PF_INET socket. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN int lttcomm_create_inet_sock(struct lttcomm_sock *sock, int type, int proto) { int val = 1, ret; @@ -78,7 +77,7 @@ error: /* * Bind socket and return. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN int lttcomm_bind_inet_sock(struct lttcomm_sock *sock) { int ret; @@ -95,7 +94,7 @@ int lttcomm_bind_inet_sock(struct lttcomm_sock *sock) /* * Connect PF_INET socket. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN int lttcomm_connect_inet_sock(struct lttcomm_sock *sock) { int ret, closeret; @@ -125,11 +124,11 @@ error_connect: * Do an accept(2) on the sock and return the new lttcomm socket. The socket * MUST be bind(2) before. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock) { int new_fd; - socklen_t len = 0; + socklen_t len; struct lttcomm_sock *new_sock; if (sock->proto == LTTCOMM_SOCK_UDP) { @@ -145,6 +144,8 @@ struct lttcomm_sock *lttcomm_accept_inet_sock(struct lttcomm_sock *sock) goto error; } + len = sizeof(new_sock->sockaddr.addr.sin); + /* Blocking call */ new_fd = accept(sock->fd, (struct sockaddr *) &new_sock->sockaddr.addr.sin, &len); @@ -167,7 +168,7 @@ error: /* * Make the socket listen using LTTNG_SESSIOND_COMM_MAX_LISTEN. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN int lttcomm_listen_inet_sock(struct lttcomm_sock *sock, int backlog) { int ret; @@ -198,13 +199,14 @@ end: * * Return the size of received data. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf, size_t len, int flags) { struct msghdr msg; struct iovec iov[1]; ssize_t ret = -1; + size_t len_last; memset(&msg, 0, sizeof(msg)); @@ -216,16 +218,21 @@ ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf, msg.msg_name = (struct sockaddr *) &sock->sockaddr.addr.sin; msg.msg_namelen = sizeof(sock->sockaddr.addr.sin); - if (flags == 0) { - flags = MSG_WAITALL; - } - do { + len_last = iov[0].iov_len; ret = recvmsg(sock->fd, &msg, flags); - } while (ret < 0 && errno == EINTR); + if (ret > 0) { + iov[0].iov_base += ret; + iov[0].iov_len -= ret; + assert(ret <= len_last); + } + } while ((ret > 0 && ret < len_last) || (ret < 0 && errno == EINTR)); if (ret < 0) { PERROR("recvmsg inet"); + } else if (ret > 0) { + ret = len; } + /* Else ret = 0 meaning an orderly shutdown. */ return ret; } @@ -235,7 +242,7 @@ ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf, * * Return the size of sent data. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf, size_t len, int flags) { @@ -278,7 +285,7 @@ ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf, /* * Shutdown cleanly and close. */ -__attribute__((visibility("hidden"))) +LTTNG_HIDDEN int lttcomm_close_inet_sock(struct lttcomm_sock *sock) { int ret;