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

Commit

Permalink
unix: omit second fcntl() call if possible
Browse files Browse the repository at this point in the history
Omit the fcntl() syscall when the O_NONBLOCK or FD_CLOEXEC is already
set/clear because it's a no-op in that case.
  • Loading branch information
bnoordhuis committed Jan 10, 2013
1 parent 9eedd32 commit 80f6a9c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/unix/core.c
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 80f6a9c

Please sign in to comment.