nl_recv_buf() must be non-blocking; enforce it with the MSG_DONTWAIT

flag.  At the same time, properly handle EINTR.
This commit is contained in:
Nicholas J. Kain 2014-03-15 04:35:07 -04:00
parent 7627298c07
commit 7bf1cc419e

View File

@ -106,11 +106,17 @@ ssize_t nl_recv_buf(int fd, char *buf, size_t blen)
.msg_iov = &iov, .msg_iov = &iov,
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
ssize_t ret = recvmsg(fd, &msg, 0); ssize_t ret;
retry:
ret = recvmsg(fd, &msg, MSG_DONTWAIT);
if (ret == -1) { if (ret == -1) {
if (errno != EAGAIN && errno != EWOULDBLOCK) if (errno == EINTR)
goto retry;
if (errno != EAGAIN && errno != EWOULDBLOCK) {
log_error("nl_fill_buf: recvmsg failed: %s", strerror(errno)); log_error("nl_fill_buf: recvmsg failed: %s", strerror(errno));
return -1; return -1;
}
return 0;
} }
if (msg.msg_flags & MSG_TRUNC) { if (msg.msg_flags & MSG_TRUNC) {
log_error("nl_fill_buf: Buffer not long enough for message."); log_error("nl_fill_buf: Buffer not long enough for message.");