diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-04-08 18:40:58 +0000 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2016-04-08 18:40:58 +0000 |
commit | 085bc845053128b653963c0c563dfa09902f3ec1 (patch) | |
tree | 7b3c2ad0c6dffad6e374f7d4d097383e7d6aa53b | |
parent | 1057677e86cd776489c9417f2d7f3a8018932891 (diff) | |
download | libmicrohttpd-085bc845053128b653963c0c563dfa09902f3ec1.tar.gz libmicrohttpd-085bc845053128b653963c0c563dfa09902f3ec1.zip |
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.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 3 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 13 |
3 files changed, 8 insertions, 14 deletions
@@ -1,3 +1,9 @@ | |||
1 | Fri Apr 08 18:32:17 CET 2016 | ||
2 | Some minor internal fixes, addition error checking and | ||
3 | micro optimizations. | ||
4 | Reworked usage of sockets shutdown() - now work equally | ||
5 | on all platforms, disconnection should be "more graceful". -EG | ||
6 | |||
1 | Tue Mar 15 21:52:27 CET 2016 | 7 | Tue Mar 15 21:52:27 CET 2016 |
2 | Do not crash if pthread_create() fails. -DD | 8 | Do not crash if pthread_create() fails. -DD |
3 | 9 | ||
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 279a335f..3aa0d16c 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -479,8 +479,7 @@ MHD_connection_close_ (struct MHD_Connection *connection, | |||
479 | 479 | ||
480 | daemon = connection->daemon; | 480 | daemon = connection->daemon; |
481 | if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) | 481 | if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO)) |
482 | shutdown (connection->socket_fd, | 482 | shutdown (connection->socket_fd, SHUT_WR); |
483 | (MHD_YES == connection->read_closed) ? SHUT_WR : SHUT_RDWR); | ||
484 | connection->state = MHD_CONNECTION_CLOSED; | 483 | connection->state = MHD_CONNECTION_CLOSED; |
485 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; | 484 | connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; |
486 | if ( (NULL != daemon->notify_completed) && | 485 | if ( (NULL != daemon->notify_completed) && |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 8ef00bd9..ea958204 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1078,9 +1078,7 @@ exit: | |||
1078 | MHD_CONNECTION_NOTIFY_CLOSED); | 1078 | MHD_CONNECTION_NOTIFY_CLOSED); |
1079 | if (MHD_INVALID_SOCKET != con->socket_fd) | 1079 | if (MHD_INVALID_SOCKET != con->socket_fd) |
1080 | { | 1080 | { |
1081 | #ifdef WINDOWS | ||
1082 | shutdown (con->socket_fd, SHUT_WR); | 1081 | shutdown (con->socket_fd, SHUT_WR); |
1083 | #endif | ||
1084 | if (0 != MHD_socket_close_ (con->socket_fd)) | 1082 | if (0 != MHD_socket_close_ (con->socket_fd)) |
1085 | MHD_PANIC ("close failed\n"); | 1083 | MHD_PANIC ("close failed\n"); |
1086 | con->socket_fd = MHD_INVALID_SOCKET; | 1084 | con->socket_fd = MHD_INVALID_SOCKET; |
@@ -2115,9 +2113,6 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
2115 | } | 2113 | } |
2116 | if (MHD_INVALID_SOCKET != pos->socket_fd) | 2114 | if (MHD_INVALID_SOCKET != pos->socket_fd) |
2117 | { | 2115 | { |
2118 | #ifdef WINDOWS | ||
2119 | shutdown (pos->socket_fd, SHUT_WR); | ||
2120 | #endif | ||
2121 | if (0 != MHD_socket_close_ (pos->socket_fd)) | 2116 | if (0 != MHD_socket_close_ (pos->socket_fd)) |
2122 | MHD_PANIC ("close failed\n"); | 2117 | MHD_PANIC ("close failed\n"); |
2123 | } | 2118 | } |
@@ -3733,11 +3728,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
3733 | daemon->socket_fd = MHD_INVALID_SOCKET; | 3728 | daemon->socket_fd = MHD_INVALID_SOCKET; |
3734 | daemon->listening_address_reuse = 0; | 3729 | daemon->listening_address_reuse = 0; |
3735 | daemon->options = flags; | 3730 | daemon->options = flags; |
3736 | #if defined(MHD_WINSOCK_SOCKETS) || defined(CYGWIN) | ||
3737 | /* Winsock is broken with respect to 'shutdown'; | ||
3738 | this disables us calling 'shutdown' on W32. */ | ||
3739 | daemon->options |= MHD_USE_EPOLL_TURBO; | ||
3740 | #endif | ||
3741 | daemon->port = port; | 3731 | daemon->port = port; |
3742 | daemon->apc = apc; | 3732 | daemon->apc = apc; |
3743 | daemon->apc_cls = apc_cls; | 3733 | daemon->apc_cls = apc_cls; |
@@ -4451,8 +4441,7 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
4451 | MHD_PANIC ("MHD_stop_daemon() called while we have suspended connections.\n"); | 4441 | MHD_PANIC ("MHD_stop_daemon() called while we have suspended connections.\n"); |
4452 | for (pos = daemon->connections_head; NULL != pos; pos = pos->next) | 4442 | for (pos = daemon->connections_head; NULL != pos; pos = pos->next) |
4453 | { | 4443 | { |
4454 | shutdown (pos->socket_fd, | 4444 | shutdown (pos->socket_fd, SHUT_RDWR); |
4455 | (MHD_YES == pos->read_closed) ? SHUT_WR : SHUT_RDWR); | ||
4456 | #if MHD_WINSOCK_SOCKETS | 4445 | #if MHD_WINSOCK_SOCKETS |
4457 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 4446 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
4458 | (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && | 4447 | (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && |