]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
net_set_nonblock(): don't replace flags in fd, change the existing ones
authorTimo Sirainen <tss@iki.fi>
Sun, 9 Nov 2003 20:20:36 +0000 (22:20 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 9 Nov 2003 20:20:36 +0000 (22:20 +0200)
--HG--
branch : HEAD

src/lib/network.c

index c2b2d28f12cebc7da54ce9f412586223c174e5fa..58990f00aec808a6a1723584cbb06225f12813ed 100644 (file)
@@ -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
 }