diff options
Diffstat (limited to 'src/lib/daemon_info.c')
-rw-r--r-- | src/lib/daemon_info.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/daemon_info.c b/src/lib/daemon_info.c new file mode 100644 index 00000000..b724094d --- /dev/null +++ b/src/lib/daemon_info.c | |||
@@ -0,0 +1,60 @@ | |||
1 | |||
2 | /** | ||
3 | * Obtain information about the given daemon | ||
4 | * (not fully implemented!). | ||
5 | * | ||
6 | * @param daemon what daemon to get information about | ||
7 | * @param info_type what information is desired? | ||
8 | * @param ... depends on @a info_type | ||
9 | * @return NULL if this information is not available | ||
10 | * (or if the @a info_type is unknown) | ||
11 | * @ingroup specialized | ||
12 | */ | ||
13 | const union MHD_DaemonInfo * | ||
14 | MHD_get_daemon_info (struct MHD_Daemon *daemon, | ||
15 | enum MHD_DaemonInfoType info_type, | ||
16 | ...) | ||
17 | { | ||
18 | if (NULL == daemon) | ||
19 | return NULL; | ||
20 | switch (info_type) | ||
21 | { | ||
22 | case MHD_DAEMON_INFO_KEY_SIZE: | ||
23 | return NULL; /* no longer supported */ | ||
24 | case MHD_DAEMON_INFO_MAC_KEY_SIZE: | ||
25 | return NULL; /* no longer supported */ | ||
26 | case MHD_DAEMON_INFO_LISTEN_FD: | ||
27 | return (const union MHD_DaemonInfo *) &daemon->listen_fd; | ||
28 | #ifdef EPOLL_SUPPORT | ||
29 | case MHD_DAEMON_INFO_EPOLL_FD: | ||
30 | return (const union MHD_DaemonInfo *) &daemon->epoll_fd; | ||
31 | #endif | ||
32 | case MHD_DAEMON_INFO_CURRENT_CONNECTIONS: | ||
33 | if (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) | ||
34 | { | ||
35 | /* Assume that MHD_run() in not called in other thread | ||
36 | * at the same time. */ | ||
37 | MHD_cleanup_connections (daemon); | ||
38 | } | ||
39 | else if (daemon->worker_pool) | ||
40 | { | ||
41 | unsigned int i; | ||
42 | /* Collect the connection information stored in the workers. */ | ||
43 | daemon->connections = 0; | ||
44 | for (i = 0; i < daemon->worker_pool_size; i++) | ||
45 | { | ||
46 | /* FIXME: next line is thread-safe only if read is atomic. */ | ||
47 | daemon->connections += daemon->worker_pool[i].connections; | ||
48 | } | ||
49 | } | ||
50 | return (const union MHD_DaemonInfo *) &daemon->connections; | ||
51 | case MHD_DAEMON_INFO_FLAGS: | ||
52 | return (const union MHD_DaemonInfo *) &daemon->options; | ||
53 | case MHD_DAEMON_INFO_BIND_PORT: | ||
54 | return (const union MHD_DaemonInfo *) &daemon->port; | ||
55 | default: | ||
56 | return NULL; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | |||