ソースを参照

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.
Evgeny Grin (Karlson2k) 9 年 前
コミット
085bc84505
3 ファイル変更8 行追加14 行削除
  1. 6 0
      ChangeLog
  2. 1 2
      src/microhttpd/connection.c
  3. 1 12
      src/microhttpd/daemon.c

+ 6 - 0
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
 

+ 1 - 2
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) &&

+ 1 - 12
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]) &&