summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-10-23 22:28:15 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-10-24 15:51:29 +0300
commitaa4da2538f101e1070b35dae41323197166fb21c (patch)
tree445ba3ee09cc45b8002632a3c3f3c2973c1a9ce6
parent08c81c49061149a4d47787058c5be84f52c60af0 (diff)
Upgrade: use socketpair only in non-blocking mode
-rw-r--r--src/microhttpd/response.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 9164d477..09e73f9b 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -742,10 +742,10 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
size_t avail;
char *buf;
MHD_socket sv[2];
-#if defined(MHD_socket_nosignal_)
+#if defined(MHD_socket_nosignal_) || !defined(MHD_socket_pair_nblk_)
int res1;
int res2;
-#endif /* MHD_socket_nosignal_ */
+#endif /* MHD_socket_nosignal_ || !MHD_socket_pair_nblk_ */
#ifdef MHD_socket_pair_nblk_
if (! MHD_socket_pair_nblk_ (sv))
@@ -759,14 +759,22 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
free (urh);
return MHD_NO;
}
- if ( (! MHD_socket_nonblocking_(sv[0])) ||
- (! MHD_socket_nonblocking_(sv[1])) )
+ res1 = MHD_socket_nonblocking_(sv[0]);
+ res2 = MHD_socket_nonblocking_(sv[1]);
+ if ( (! res1) || (! res2) )
{
#ifdef HAVE_MESSAGES
MHD_DLOG (daemon,
- _("Failed to make loopback sockets non-blocking: %s\n"),
- MHD_socket_last_strerr_ ());
+ _("Failed to make loopback sockets non-blocking.\n"));
#endif
+ if (! res2)
+ {
+ /* Socketpair cannot be used. */
+ MHD_socket_close_chk_ (sv[0]);
+ MHD_socket_close_chk_ (sv[1]);
+ free (urh);
+ return MHD_NO;
+ }
}
#endif /* !MHD_socket_pair_nblk_ */
#ifdef MHD_socket_nosignal_