From e602c2b271c4efdd0f9138863fb16f5b790fb824 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 27 Oct 2014 11:10:48 -0400 Subject: [PATCH 1/2] src/usocket: Do not setblocking on destroy; This results in unexpected behaviour if the socket has been `dup()`d, as O_NONBLOCK is shared. Close is always 'blocking' anyway See https://github.com/wahern/cqueues/issues/13 for an example use case --- src/usocket.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/usocket.c b/src/usocket.c index 096ecd0..ca483f4 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -92,7 +92,6 @@ int socket_close(void) { \*-------------------------------------------------------------------------*/ void socket_destroy(p_socket ps) { if (*ps != SOCKET_INVALID) { - socket_setblocking(ps); close(*ps); *ps = SOCKET_INVALID; } From 4f122e60b147107a0a5ca7a8dff698a47794e30c Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 27 Oct 2014 14:03:34 -0400 Subject: [PATCH 2/2] src/usocket: Don't unset/set O_NONBLOCK around listen() or shutdown() calls. It doesn't effect them. Not true on windows --- src/usocket.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/usocket.c b/src/usocket.c index ca483f4..89f774d 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -139,9 +139,7 @@ int socket_bind(p_socket ps, SA *addr, socklen_t len) { \*-------------------------------------------------------------------------*/ int socket_listen(p_socket ps, int backlog) { int err = IO_DONE; - socket_setblocking(ps); if (listen(*ps, backlog)) err = errno; - socket_setnonblocking(ps); return err; } @@ -149,9 +147,7 @@ int socket_listen(p_socket ps, int backlog) { * \*-------------------------------------------------------------------------*/ void socket_shutdown(p_socket ps, int how) { - socket_setblocking(ps); shutdown(*ps, how); - socket_setnonblocking(ps); } /*-------------------------------------------------------------------------*\