From: Timo Sirainen Date: Sun, 9 Nov 2003 20:20:36 +0000 (+0200) Subject: net_set_nonblock(): don't replace flags in fd, change the existing ones X-Git-Tag: 1.1.alpha1~4235 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cfcabf9ea2473db650ddf18864233f68ead2c2b;p=thirdparty%2Fdovecot%2Fcore.git net_set_nonblock(): don't replace flags in fd, change the existing ones --HG-- branch : HEAD --- diff --git a/src/lib/network.c b/src/lib/network.c index c2b2d28f12..58990f00ae 100644 --- a/src/lib/network.c +++ b/src/lib/network.c @@ -194,7 +194,18 @@ void net_disconnect(int fd) void net_set_nonblock(int fd __attr_unused__, int nonblock __attr_unused__) { #ifdef HAVE_FCNTL - if (fcntl(fd, F_SETFL, nonblock ? O_NONBLOCK : 0) < 0) + int flags; + + flags = fcntl(fd, F_GETFL, 0); + if (flags == -1) + i_fatal("net_set_nonblock() failed: %m"); + + if (nonblock) + flags |= O_NONBLOCK; + else + flags &= ~O_NONBLOCK; + + if (fcntl(fd, F_SETFL, flags) < 0) i_fatal("net_set_nonblock() failed: %m"); #endif }