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.
This commit is contained in:
Ben Noordhuis 2012-08-21 14:44:07 +02:00
parent 37173f8515
commit b12b6498d6

View File

@ -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
@ -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