libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit da7e8ad76dcec43b011ea65a20b7b45608590f34
parent 2160c665890c35077ed7322a330337434f22d2ed
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 12 Oct 2011 08:41:49 +0000

fixing #1824

Diffstat:
MChangeLog | 5+++++
Msrc/daemon/daemon.c | 51++++++++++++++++-----------------------------------
2 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Wed Oct 12 10:40:12 CEST 2011 + Made sockets blocking again for non-Linux platforms as non-blocking + sockets cause problems (#1824) on Cygwin but offer better performance + on Linux (see change on August 11 2011). -CG/pross + Fri Oct 7 19:50:07 CEST 2011 Fixed problems with testcases on W32. -LRN diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -768,40 +768,6 @@ send_param_adapter (struct MHD_Connection *connection, /** - * Set if a socket should use non-blocking IO. - * @param fd socket - */ -static void -socket_set_nonblocking (int fd) -{ -#if MINGW - u_long mode; - mode = 1; - if (ioctlsocket (fd, FIONBIO, &mode) == SOCKET_ERROR) - { - SetErrnoFromWinsockError (WSAGetLastError ()); -#if HAVE_MESSAGES - FPRINTF(stderr, "Failed to make socket non-blocking: %s\n", - STRERROR (errno)); -#endif - } -#else - - /* not MINGW */ - int flags = fcntl (fd, F_GETFL); - if ( (flags == -1) || - (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) ) - { -#if HAVE_MESSAGES - FPRINTF(stderr, "Failed to make socket non-blocking: %s\n", - STRERROR (errno)); -#endif - } -#endif -} - - -/** * Create a thread and set the attributes according to our options. * * @param thread handle to initialize @@ -979,7 +945,22 @@ MHD_add_connection (struct MHD_Daemon *daemon, MHD_set_http_callbacks_ (connection); connection->recv_cls = &recv_param_adapter; connection->send_cls = &send_param_adapter; - socket_set_nonblocking (connection->socket_fd); +#if LINUX + { + /* non-blocking sockets perform better on Linux */ + int flags = fcntl (fd, F_GETFL); + if ( (flags == -1) || + (0 != fcntl (fd, F_SETFL, flags | O_NONBLOCK)) ) + { +#if HAVE_MESSAGES + FPRINTF(stderr, "Failed to make socket non-blocking: %s\n", + STRERROR (errno)); +#endif + } +#endif + } +#endif + #if HTTPS_SUPPORT if (0 != (daemon->options & MHD_USE_SSL)) {