Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix: make uv__nonblock() EINTR resilient

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 94cb06fecfb27ca252e1a4a2ac83488ff1787f23
Showing with 20 additions and 12 deletions.
  1. +20 −12 src/unix/core.c
@@ -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
}

0 comments on commit 94cb06f

Please sign in to comment.
You can’t perform that action at this time.