libmicrohttpd

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

commit 085bc845053128b653963c0c563dfa09902f3ec1
parent 1057677e86cd776489c9417f2d7f3a8018932891
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Fri,  8 Apr 2016 18:40:58 +0000

Reworked calling shutdown() on connections:

Now called on all platforms (including W32), called only with SHUT_WR,
except in close_all_connections() where shutdown() called with SHUT_RDWR.
This should increase chances of graceful disconnection.

Diffstat:
MChangeLog | 6++++++
Msrc/microhttpd/connection.c | 3+--
Msrc/microhttpd/daemon.c | 13+------------
3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,9 @@ +Fri Apr 08 18:32:17 CET 2016 + Some minor internal fixes, addition error checking and + micro optimizations. + Reworked usage of sockets shutdown() - now work equally + on all platforms, disconnection should be "more graceful". -EG + Tue Mar 15 21:52:27 CET 2016 Do not crash if pthread_create() fails. -DD diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -479,8 +479,7 @@ MHD_connection_close_ (struct MHD_Connection *connection, daemon = connection->daemon; if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) - shutdown (connection->socket_fd, - (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR); + shutdown (connection->socket_fd, SHUT_WR); connection->state = MHD_CONNECTION_CLOSED; connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; if ( (NULL != daemon->notify_completed) && diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -1078,9 +1078,7 @@ exit: MHD_CONNECTION_NOTIFY_CLOSED); if (MHD_INVALID_SOCKET != con->socket_fd) { -#ifdef WINDOWS shutdown (con->socket_fd, SHUT_WR); -#endif if (0 != MHD_socket_close_ (con->socket_fd)) MHD_PANIC ("close failed\n"); con->socket_fd = MHD_INVALID_SOCKET; @@ -2115,9 +2113,6 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) } if (MHD_INVALID_SOCKET != pos->socket_fd) { -#ifdef WINDOWS - shutdown (pos->socket_fd, SHUT_WR); -#endif if (0 != MHD_socket_close_ (pos->socket_fd)) MHD_PANIC ("close failed\n"); } @@ -3733,11 +3728,6 @@ MHD_start_daemon_va (unsigned int flags, daemon->socket_fd = MHD_INVALID_SOCKET; daemon->listening_address_reuse = 0; daemon->options = flags; -#if defined(MHD_WINSOCK_SOCKETS) || defined(CYGWIN) - /* Winsock is broken with respect to 'shutdown'; - this disables us calling 'shutdown' on W32. */ - daemon->options |= MHD_USE_EPOLL_TURBO; -#endif daemon->port = port; daemon->apc = apc; daemon->apc_cls = apc_cls; @@ -4451,8 +4441,7 @@ close_all_connections (struct MHD_Daemon *daemon) MHD_PANIC ("MHD_stop_daemon() called while we have suspended connections.\n"); for (pos = daemon->connections_head; NULL != pos; pos = pos->next) { - shutdown (pos->socket_fd, - (MHD_YES == pos->read_closed) ? SHUT_WR : SHUT_RDWR); + shutdown (pos->socket_fd, SHUT_RDWR); #if MHD_WINSOCK_SOCKETS if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&