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:
parent
7627298c07
commit
7bf1cc419e
12
ndhc/nl.c
12
ndhc/nl.c
@ -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.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user