libmicrohttpd

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

commit 774e50c035a357638357dae113c4646f2791ccfa
parent b6db4c24d40321a2e617147793bac471dc0a0a65
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 18 Nov 2014 12:54:01 +0000

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



Diffstat:
MChangeLog | 4++++
Msrc/microhttpd/daemon.c | 6+++++-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/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 diff --git a/src/microhttpd/daemon.c b/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: