struct msghdr msg;
struct iovec iov[1];
ssize_t ret = -1;
+ size_t len_last;
memset(&msg, 0, sizeof(msg));
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;
}
char dummy = 0;
memset(&msg, 0, sizeof(msg));
+ memset(tmp, 0, CMSG_SPACE(sizeof_fds) * sizeof(char));
if (nb_fd > LTTCOMM_MAX_SEND_FDS)
return -EINVAL;
#endif /* __linux__ */
memset(&msg, 0, sizeof(msg));
+ memset(anc_buf, 0, CMSG_SPACE(sizeof_cred) * sizeof(char));
iov[0].iov_base = buf;
iov[0].iov_len = len;
#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;
+}