[Nbd] [PATCH 08/11] nbd-server: do not call fcntl F_SETFL unnecessarily
- To: nbd-general@lists.sourceforge.net
- Subject: [Nbd] [PATCH 08/11] nbd-server: do not call fcntl F_SETFL unnecessarily
- From: "Dmitry V. Levin" <ldv@...1147...>
- Date: Fri, 22 Jun 2012 01:43:07 +0400
- Message-id: <20120621214307.GH26247@...1147...>
Call fcntl F_SETFL only when new file status flags differ from the old one.
Signed-off-by: Dmitry V. Levin <ldv@...1147...>
---
nbd-server.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/nbd-server.c b/nbd-server.c
index cd8fdb9..3e64c37 100644
--- a/nbd-server.c
+++ b/nbd-server.c
@@ -2165,7 +2165,8 @@ void destroy_pid_t(gpointer data) {
static void
handle_connection(GArray *servers, int net, SERVER *serve, CLIENT *client)
{
- int sock_flags;
+ int sock_flags_old;
+ int sock_flags_new;
if(serve->max_connections > 0 &&
g_hash_table_size(children) >= serve->max_connections) {
@@ -2173,10 +2174,12 @@ handle_connection(GArray *servers, int net, SERVER *serve, CLIENT *client)
close(net);
return;
}
- if((sock_flags = fcntl(net, F_GETFL, 0))==-1) {
+ if((sock_flags_old = fcntl(net, F_GETFL, 0)) == -1) {
err("fcntl F_GETFL");
}
- if(fcntl(net, F_SETFL, sock_flags &~O_NONBLOCK)==-1) {
+ sock_flags_new = sock_flags_old & ~O_NONBLOCK;
+ if (sock_flags_new != sock_flags_old &&
+ fcntl(net, F_SETFL, sock_flags_new) == -1) {
err("fcntl F_SETFL ~O_NONBLOCK");
}
if(!client) {
--
ldv
Reply to: