libmicrohttpd

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

commit d50980a7658b28dd928dcdb379360492b5db1aa1
parent e38d4e283edcdadb800f1b7413a46555ee5df817
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 29 Oct 2014 15:29:31 +0000

From: Milan Straka <fox@ucw.cz>
Date: Wed, 29 Oct 2014 09:59:09 +0100
Subject: [PATCH 2/2] Add MHD_DAEMON_INFO_CURRENT_CONNECTIONS to
 MHD_DaemonInfoType.

The MHD_DAEMON_INFO_CURRENT_CONNECTIONS returns number of current
connections handled by the daemon.

Useful after MHD_quiesce_daemon to find out whether all connections
have been served.


Diffstat:
MAUTHORS | 1+
MChangeLog | 4++++
Mdoc/libmicrohttpd.texi | 22++++++++++++++++++----
Msrc/include/microhttpd.h | 20++++++++++++++++----
Msrc/microhttpd/daemon.c | 11+++++++++++
5 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/AUTHORS b/AUTHORS @@ -25,6 +25,7 @@ David Carvalho <andaris@gmail.com> David Reiss <dreiss@facebook.com> Matt Holiday Michael Cronenworth <mike@cchtml.com> +Milan Straka <straka@ufal.mff.cuni.cz> Mika Raento <mikie@iki.fi> Mike Crowe <mac@mcrowe.com> John Muth <muth@parascale.com> diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Wed Oct 29 16:27:05 CET 2014 + Adding MHD_DAEMON_INFO_CURRENT_CONNECTIONS to allow clients + to query the number of active connections. -MS + Fri Oct 3 14:28:58 CEST 2014 Releasing 0.9.38. -CG diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi @@ -2394,13 +2394,13 @@ information about a daemon is desired. Request information about the key size for a particular cipher algorithm. The cipher algorithm should be passed as an extra argument (of type 'enum MHD_GNUTLS_CipherAlgorithm'). No longer supported, -using this value will cause MHD_get_daemon_info to return NULL. +using this value will cause @code{MHD_get_daemon_info} to return NULL. @item MHD_DAEMON_INFO_MAC_KEY_SIZE Request information about the key size for a particular cipher algorithm. The cipher algorithm should be passed as an extra argument (of type 'enum MHD_GNUTLS_HashAlgorithm'). No longer supported, -using this value will cause MHD_get_daemon_info to return NULL. +using this value will cause @code{MHD_get_daemon_info} to return NULL. @item MHD_DAEMON_INFO_LISTEN_FD @cindex listen @@ -2415,12 +2415,26 @@ No extra arguments should be passed. Request the file-descriptor number that MHD is using for epoll. If the build is not supporting epoll, NULL is returned; if we are using a thread pool or this daemon was not started with -MHD_USE_EPOLL_LINUX_ONLY, (a pointer to) -1 is returned. If we are -using MHD_USE_SELECT_INTERNALLY or are in 'external' select mode, the +@code{MHD_USE_EPOLL_LINUX_ONLY}, (a pointer to) -1 is returned. If we are +using @code{MHD_USE_SELECT_INTERNALLY} or are in 'external' select mode, the internal epoll FD is returned. This function must be used in external select mode with epoll to obtain the FD to call epoll on. No extra arguments should be passed. +@item MHD_DAEMON_INFO_CURRENT_CONNECTIONS +@cindex connection, limiting number of connections +Request the number of current connections handled by the daemon. No +extra arguments should be passed and a pointer to a @code{union +MHD_DaemonInfo} value is returned, with the @code{num_connections} +member of type @code{unsigned int} set to the number of active +connections. + +Note that in multi-threaded or internal-select mode, the real number of current +connections may already be different when @code{MHD_get_daemon_info} returns. +The number of current connections can be used (even in multi-threaded and +internal-select mode) after @code{MHD_quiesce_daemon} to detect whether all +connections have been handled. + @end table @end deftp diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -1111,7 +1111,13 @@ enum MHD_DaemonInfoType * Request the file descriptor for the external epoll. * No extra arguments should be passed. */ - MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY + MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY, + + /** + * Request the number of current connections handled by the daemon. + * No extra arguments should be passed. + */ + MHD_DAEMON_INFO_CURRENT_CONNECTIONS, }; @@ -2369,21 +2375,27 @@ MHD_set_connection_option (struct MHD_Connection *connection, union MHD_DaemonInfo { /** - * Size of the key. + * Size of the key, no longer supported. * @deprecated */ size_t key_size; /** - * Size of the mac key. + * Size of the mac key, no longer supported. * @deprecated */ size_t mac_key_size; /** - * Listen socket file descriptor + * Listen socket file descriptor, for #MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY + * and #MHD_DAEMON_INFO_LISTEN_FD. */ MHD_socket listen_fd; + + /** + * Number of active connections, for #MHD_DAEMON_INFO_CURRENT_CONNECTIONS. + */ + unsigned int num_connections; }; diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -4232,6 +4232,17 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon, case MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY: return (const union MHD_DaemonInfo *) &daemon->epoll_fd; #endif + case MHD_DAEMON_INFO_CURRENT_CONNECTIONS: + if (daemon->worker_pool) + { + /* Collect the connection information stored in the workers. */ + unsigned int i; + + daemon->connections = 0; + for (i=0;i<daemon->worker_pool_size;i++) + daemon->connections += daemon->worker_pool[i].connections; + } + return (const union MHD_DaemonInfo *) &daemon->connections; default: return NULL; };