Unverified Commit 5198b513 authored by Andy Pan's avatar Andy Pan Committed by GitHub
Browse files

Add a precheck before the actual call to fcntl (#8360)

Don't bother to call fcntl if the flags are not gonna be changed.
parent 366a16ff
...@@ -69,6 +69,11 @@ int anetSetBlock(char *err, int fd, int non_block) { ...@@ -69,6 +69,11 @@ int anetSetBlock(char *err, int fd, int non_block) {
return ANET_ERR; return ANET_ERR;
} }
/* Check if this flag has been set or unset, if so,
* then there is no need to call fcntl to set/unset it again. */
if (!!(flags & O_NONBLOCK) == !!non_block)
return ANET_OK;
if (non_block) if (non_block)
flags |= O_NONBLOCK; flags |= O_NONBLOCK;
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment