From b12b6498d612990a1f5375148a5bde456e7efddf Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 21 Aug 2012 14:44:07 +0200 Subject: [PATCH] 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. --- src/unix/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/unix/core.c b/src/unix/core.c index 1d6d9cae..85d5f164 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -49,10 +49,14 @@ #ifdef __APPLE__ # include /* _NSGetExecutablePath */ +# include +# include #endif #ifdef __FreeBSD__ # include +# include +# include # include #endif @@ -503,7 +507,7 @@ skip: } -#if __linux__ +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) int uv__nonblock(int fd, int set) { int r; @@ -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; @@ -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