Remove MSG_WAITALL on every recvmsg() socket type
[lttng-tools.git] / src / common / sessiond-comm / unix.c
index 9ef04ee0df1943ce41b4ca886ee2913d27d21619..bbf030f67f6bc0cef88b956af83da132f548bd57 100644 (file)
@@ -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;
+}
This page took 0.023932 seconds and 4 git commands to generate.