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

Commit

Permalink
Browse files Browse the repository at this point in the history
darwin, freebsd: use ioctl(FIOCLEX) and ioctl(FIONBIO)
Set the non-blocking and close-on-exec flags with ioctl() instead of fcntl(),
it's about 10-25% faster.

Stick with fcntl() on Solaris. ioctl(FIONBIO) works but is twice as slow as
fcntl(O_NONBLOCK). ioctl(FIOCLEX) doesn't raise an error but doesn't actually
work either.
  • Loading branch information
bnoordhuis committed Aug 21, 2012
1 parent 37173f8 commit b12b649
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/unix/core.c
Expand Up @@ -49,10 +49,14 @@

#ifdef __APPLE__
# include <mach-o/dyld.h> /* _NSGetExecutablePath */
# include <sys/filio.h>
# include <sys/ioctl.h>
#endif

#ifdef __FreeBSD__
# include <sys/sysctl.h>
# include <sys/filio.h>
# include <sys/ioctl.h>
# include <sys/wait.h>
#endif

Expand Down Expand Up @@ -503,7 +507,7 @@ int uv__accept(int sockfd) {
}


#if __linux__
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)

int uv__nonblock(int fd, int set) {
int r;
Expand All @@ -526,7 +530,7 @@ int uv__cloexec(int fd, int set) {
return r;
}

#else /* !__linux__ */
#else /* !(defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) */

int uv__nonblock(int fd, int set) {
int flags;
Expand Down Expand Up @@ -575,7 +579,7 @@ int uv__cloexec(int fd, int set) {
return r;
}

#endif /* __linux__ */
#endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) */


/* This function is not execve-safe, there is a race window
Expand Down

0 comments on commit b12b649

Please sign in to comment.