diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-03-16 17:57:46 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-03-16 17:57:46 +0300 |
commit | 7764a946fd1c051dea59b0e3404a371a34319572 (patch) | |
tree | cd441b10d83a283d0c65dfaa420532aa63978cae /src/microhttpd | |
parent | b3e48b50908ebd754da1fac9cc3b26d567413daa (diff) | |
download | libmicrohttpd-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
Diffstat (limited to 'src/microhttpd')
-rw-r--r-- | src/microhttpd/daemon.c | 18 |
1 files changed, 12 insertions, 6 deletions
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 | } |