X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fsessiond-comm%2Funix.c;h=bbf030f67f6bc0cef88b956af83da132f548bd57;hp=9ef04ee0df1943ce41b4ca886ee2913d27d21619;hb=7c5aef6226a4752f3a4e60cd0b52c741dced395e;hpb=32dd26fbc3c69fe677a7917535e10ace066e674c diff --git a/src/common/sessiond-comm/unix.c b/src/common/sessiond-comm/unix.c index 9ef04ee0d..bbf030f67 100644 --- a/src/common/sessiond-comm/unix.c +++ b/src/common/sessiond-comm/unix.c @@ -157,6 +157,7 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) struct msghdr msg; struct iovec iov[1]; ssize_t ret = -1; + size_t len_last; memset(&msg, 0, sizeof(msg)); @@ -166,11 +167,20 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) msg.msg_iovlen = 1; do { - ret = recvmsg(sock, &msg, MSG_WAITALL); - } while (ret < 0 && errno == EINTR); + len_last = iov[0].iov_len; + ret = recvmsg(sock, &msg, 0); + 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"); + } else if (ret > 0) { + ret = len; } + /* Else ret = 0 meaning an orderly shutdown. */ return ret; } @@ -523,3 +533,45 @@ int lttcomm_setsockopt_creds_unix_sock(int sock) #else #error "Please implement credential support for your OS." #endif /* __linux__ */ + +/* + * Set socket reciving timeout. + */ +__attribute__((visibility("hidden"))) +int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int sec) +{ + int ret; + struct timeval tv; + + tv.tv_sec = sec; + tv.tv_usec = 0; + + ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + if (ret < 0) { + PERROR("setsockopt SO_RCVTIMEO"); + ret = -errno; + } + + return ret; +} + +/* + * Set socket sending timeout. + */ +__attribute__((visibility("hidden"))) +int lttcomm_setsockopt_snd_timeout(int sock, unsigned int sec) +{ + int ret; + struct timeval tv; + + tv.tv_sec = sec; + tv.tv_usec = 0; + + ret = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + if (ret < 0) { + PERROR("setsockopt SO_SNDTIMEO"); + ret = -errno; + } + + return ret; +}