aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-03-16 17:57:46 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-03-16 17:57:46 +0300
commit7764a946fd1c051dea59b0e3404a371a34319572 (patch)
treecd441b10d83a283d0c65dfaa420532aa63978cae
parentb3e48b50908ebd754da1fac9cc3b26d567413daa (diff)
downloadlibmicrohttpd-7764a946fd1c051dea59b0e3404a371a34319572.tar.gz
libmicrohttpd-7764a946fd1c051dea59b0e3404a371a34319572.zip
Fixed thread-safety of MHD_get_daemon_info() for MHD_DAEMON_INFO_CURRENT_CONNECTIONS,
Updated MHD_DAEMON_INFO_CURRENT_CONNECTIONS description
-rw-r--r--src/include/microhttpd.h3
-rw-r--r--src/microhttpd/daemon.c18
2 files changed, 15 insertions, 6 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 79f57a19..4749a6ee 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -1795,6 +1795,9 @@ enum MHD_DaemonInfoType
1795 /** 1795 /**
1796 * Request the number of current connections handled by the daemon. 1796 * Request the number of current connections handled by the daemon.
1797 * No extra arguments should be passed. 1797 * No extra arguments should be passed.
1798 * Note: when using MHD in external polling mode, this type of request
1799 * could be used only when #MHD_run()/#MHD_run_from_select is not
1800 * working in other thread at the same time.
1798 */ 1801 */
1799 MHD_DAEMON_INFO_CURRENT_CONNECTIONS, 1802 MHD_DAEMON_INFO_CURRENT_CONNECTIONS,
1800 1803
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 185421c7..001c3586 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -6234,6 +6234,8 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
6234 enum MHD_DaemonInfoType info_type, 6234 enum MHD_DaemonInfoType info_type,
6235 ...) 6235 ...)
6236{ 6236{
6237 if (NULL == daemon)
6238 return NULL;
6237 switch (info_type) 6239 switch (info_type)
6238 { 6240 {
6239 case MHD_DAEMON_INFO_KEY_SIZE: 6241 case MHD_DAEMON_INFO_KEY_SIZE:
@@ -6247,16 +6249,20 @@ MHD_get_daemon_info (struct MHD_Daemon *daemon,
6247 return (const union MHD_DaemonInfo *) &daemon->epoll_fd; 6249 return (const union MHD_DaemonInfo *) &daemon->epoll_fd;
6248#endif 6250#endif
6249 case MHD_DAEMON_INFO_CURRENT_CONNECTIONS: 6251 case MHD_DAEMON_INFO_CURRENT_CONNECTIONS:
6250 MHD_cleanup_connections (daemon); 6252 if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD))
6251 if (daemon->worker_pool) 6253 {
6254 /* Assume that MHD_run() in not called in other thread
6255 * at the same time. */
6256 MHD_cleanup_connections (daemon);
6257 }
6258 else if (daemon->worker_pool)
6252 { 6259 {
6253 /* Collect the connection information stored in the workers. */
6254 unsigned int i; 6260 unsigned int i;
6255 6261 /* Collect the connection information stored in the workers. */
6256 daemon->connections = 0; 6262 daemon->connections = 0;
6257 for (i=0;i<daemon->worker_pool_size;i++) 6263 for (i = 0; i < daemon->worker_pool_size; i++)
6258 { 6264 {
6259 MHD_cleanup_connections (&daemon->worker_pool[i]); 6265 /* FIXME: next line is thread-safe only if read is atomic. */
6260 daemon->connections += daemon->worker_pool[i].connections; 6266 daemon->connections += daemon->worker_pool[i].connections;
6261 } 6267 }
6262 } 6268 }