Skip to content

Commit

Permalink
Handle EINTR in sys_sendmsgfd() and sys_recvmsgfd()
Browse files Browse the repository at this point in the history
  • Loading branch information
droe committed Nov 23, 2014
1 parent 2d97659 commit a09f42a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ sys_sendmsgfd(int sock, void *buf, size_t bufsz, int fd)
struct msghdr msg;
struct cmsghdr *cmsg;
char cmsgbuf[CMSG_SPACE(sizeof(int))];
ssize_t n;

iov.iov_base = buf;
iov.iov_len = bufsz;
Expand All @@ -533,11 +534,14 @@ sys_sendmsgfd(int sock, void *buf, size_t bufsz, int fd)
msg.msg_control = NULL;
msg.msg_controllen = 0;
}
do {
#ifdef MSG_NOSIGNAL
return sendmsg(sock, &msg, MSG_NOSIGNAL);
n = sendmsg(sock, &msg, MSG_NOSIGNAL);
#else /* !MSG_NOSIGNAL */
return sendmsg(sock, &msg, 0);
n = sendmsg(sock, &msg, 0);
#endif /* !MSG_NOSIGNAL */
} while (n == -1 && errno == EINTR);
return n;
}

/*
Expand Down Expand Up @@ -567,7 +571,10 @@ sys_recvmsgfd(int sock, void *buf, size_t bufsz, int *pfd)
msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
if ((n = recvmsg(sock, &msg, 0)) <= 0)
do {
n = recvmsg(sock, &msg, 0);
} while (n == -1 && errno == EINTR);
if (n <= 0)
return n;
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
Expand All @@ -584,7 +591,9 @@ sys_recvmsgfd(int sock, void *buf, size_t bufsz, int *pfd)
*pfd = -1;
}
} else {
n = recv(sock, buf, bufsz, 0);
do {
n = recv(sock, buf, bufsz, 0);
} while (n == -1 && errno == EINTR);
}
return n;
}
Expand Down

0 comments on commit a09f42a

Please sign in to comment.