unix: omit second fcntl() call if possible

Omit the fcntl() syscall when the O_NONBLOCK or FD_CLOEXEC is already
set/clear because it's a no-op in that case.
This commit is contained in:
Ben Noordhuis 2013-01-10 01:20:05 +01:00
parent 9eedd32e40
commit 80f6a9c643

View File

@ -444,6 +444,10 @@ int uv__nonblock(int fd, int set) {
if (r == -1)
return -1;
/* Bail out now if already set/clear. */
if (!!(r & O_NONBLOCK) == !!set)
return 0;
if (set)
flags = r | O_NONBLOCK;
else
@ -468,6 +472,10 @@ int uv__cloexec(int fd, int set) {
if (r == -1)
return -1;
/* Bail out now if already set/clear. */
if (!!(r & FD_CLOEXEC) == !!set)
return 0;
if (set)
flags = r | FD_CLOEXEC;
else