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 366a16ff05
commit 5198b513d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,6 +69,11 @@ int anetSetBlock(char *err, int fd, int non_block) {
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)
flags |= O_NONBLOCK;
else