commit aa4da2538f101e1070b35dae41323197166fb21c
parent 08c81c49061149a4d47787058c5be84f52c60af0
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Sun, 23 Oct 2016 22:28:15 +0300
Upgrade: use socketpair only in non-blocking mode
Diffstat:
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git 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_