From 6fc0b5d2b6a482f4e9eb0fa672f82c760af305b8 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Tue, 19 Jan 2021 17:36:21 +0800 Subject: [PATCH] Add a precheck before the actual call to fcntl (#8360) Don't bother to call fcntl if the flags are not gonna be changed. --- src/anet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/anet.c b/src/anet.c index 7a0a1b1ed..4e2e6be88 100644 --- a/src/anet.c +++ b/src/anet.c @@ -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