From 80f6a9c643f56521731a7f51b65100fbc8913c39 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 10 Jan 2013 01:20:05 +0100 Subject: [PATCH] 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. --- src/unix/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/unix/core.c b/src/unix/core.c index 1154fa25..b4cb948b 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -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