Просмотр исходного кода

Hi Christian,

the recently added MHD_DAEMON_INFO_CURRENT_CONNECTIONS can return quite
outdated values in MHD_USE_THREAD_PER_CONNECTION mode. The reason is
that closed connections are collected in MHD_cleanup_connections, which
is called only from the select thread. In the
MHD_USE_THREAD_PER_CONNECTION mode that happens only after accepting an
connection -- therefore, the last connection is always not collected and
MHD_DAEMON_INFO_CURRENT_CONNECTIONS returns >= 1, even when there are no
connections. That makes it very unusable to detect whether all
connections have been handled.

Would you consider the attached patch, which calls
MHD_cleanup_connections whenever MHD_DAEMON_INFO_CURRENT_CONNECTIONS is
called? It makes MHD_DAEMON_INFO_CURRENT_CONNECTIONS slower, but the
returned value is much more accurate.

Cheers,
Milan Straka
Christian Grothoff 11 лет назад
Родитель
Сommit
774e50c035
2 измененных файлов с 9 добавлено и 1 удалено
  1. 4 0
      ChangeLog
  2. 5 1
      src/microhttpd/daemon.c

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+Tue Nov 18 13:52:29 CET 2014
+	Call MHD_cleanup_connections() during MHD_DAEMON_INFO_CURRENT_CONNECTIONS
+	processing for more accurate results. -MS
+
 Wed Oct 29 20:45:21 CET 2014
 	Adding MHD_OPTION_LISTENING_ADDRESS_REUSE option allowing clients
 	to force allowing re-use of the address:port combination

+ 5 - 1
src/microhttpd/daemon.c

@@ -4344,6 +4344,7 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
       return (const union MHD_DaemonInfo *) &daemon->epoll_fd;
 #endif
     case MHD_DAEMON_INFO_CURRENT_CONNECTIONS:
+      MHD_cleanup_connections (daemon);
       if (daemon->worker_pool)
         {
           /* Collect the connection information stored in the workers. */
@@ -4351,7 +4352,10 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
 
           daemon->connections = 0;
           for (i=0;i<daemon->worker_pool_size;i++)
-            daemon->connections += daemon->worker_pool[i].connections;
+            {
+              MHD_cleanup_connections (&daemon->worker_pool[i]);
+              daemon->connections += daemon->worker_pool[i].connections;
+            }
         }
       return (const union MHD_DaemonInfo *) &daemon->connections;
     default: