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

Don't bother to call fcntl if the flags are not gonna be changed.
This commit is contained in:
Andy Pan 2021-01-19 17:36:21 +08:00 committed by GitHub
parent c5b13b7815
commit 6fc0b5d2b6

View File

@ -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