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:
parent
9eedd32e40
commit
80f6a9c643
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user