Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: make uv__nonblock() EINTR resilient
Browse files Browse the repository at this point in the history
It's underspecified if and when ioctl(FIONBIO) or fcntl() can return EINTR.
Let's take the safe route.
  • Loading branch information
bnoordhuis authored and piscisaureus committed Jun 13, 2012
1 parent b3a97f8 commit 94cb06f
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/unix/core.c
Expand Up @@ -462,26 +462,34 @@ int uv__accept(int sockfd) {


int uv__nonblock(int fd, int set) {
int r;

#if FIONBIO
return ioctl(fd, FIONBIO, &set);
do
r = ioctl(fd, FIONBIO, &set);
while (r == -1 && errno == EINTR);

return r;
#else
int flags;

if ((flags = fcntl(fd, F_GETFL)) == -1) {
do
r = fcntl(fd, F_GETFL);
while (r == -1 && errno == EINTR);

if (r == -1)
return -1;
}

if (set) {
flags |= O_NONBLOCK;
} else {
flags &= ~O_NONBLOCK;
}
if (set)
flags = r | O_NONBLOCK;
else
flags = r & ~O_NONBLOCK;

if (fcntl(fd, F_SETFL, flags) == -1) {
return -1;
}
do
r = fcntl(fd, F_SETFL, flags);
while (r == -1 && errno == EINTR);

return 0;
return r;
#endif
}

Expand Down

0 comments on commit 94cb06f

Please sign in to comment.