GNU libmicrohttpd 0.9.77
Loading...
Searching...
No Matches
daemon_info.c
Go to the documentation of this file.
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
25#include "internal.h"
26#include "connection_cleanup.h"
27
28
44enum MHD_Bool
46 enum MHD_DaemonInformationType info_type,
47 union MHD_DaemonInformation *return_value,
48 size_t return_value_size)
49{
50#define CHECK_SIZE(type) if (sizeof(type) < return_value_size) \
51 return MHD_NO
52
53 switch (info_type)
54 {
55 case MHD_DAEMON_INFORMATION_LISTEN_SOCKET:
57 return_value->listen_socket
58 = daemon->listen_socket;
59 return MHD_YES;
60#ifdef EPOLL_SUPPORT
61 case MHD_DAEMON_INFORMATION_EPOLL_FD:
62 CHECK_SIZE (int);
63 // FIXME: maybe return MHD_NO if we are not using EPOLL?
64 return_value->epoll_fd = daemon->epoll_fd;
65 return MHD_YES;
66#endif
67 case MHD_DAEMON_INFORMATION_CURRENT_CONNECTIONS:
68 CHECK_SIZE (unsigned int);
69 if (MHD_TM_EXTERNAL_EVENT_LOOP == daemon->threading_mode)
70 {
71 /* Assumes that MHD_run() in not called in other thread
72 (of the application) at the same time. */
74 return_value->num_connections
75 = daemon->connections;
76 }
77 else if (daemon->worker_pool)
78 {
79 unsigned int i;
80 /* Collect the connection information stored in the workers. */
81 return_value->num_connections = 0;
82 for (i = 0; i < daemon->worker_pool_size; i++)
83 {
84 /* FIXME: next line is thread-safe only if read is atomic. */
85 return_value->num_connections
86 += daemon->worker_pool[i].connections;
87 }
88 }
89 else
90 return_value->num_connections
91 = daemon->connections;
92 return MHD_YES;
93 case MHD_DAEMON_INFORMATION_BIND_PORT:
94 CHECK_SIZE (uint16_t);
95 // FIXME: return MHD_NO if port is not known/UNIX?
96 return_value->port = daemon->listen_port;
97 return MHD_YES;
98 default:
99 return MHD_NO;
100 }
101
102#undef CHECK_SIZE
103}
104
105
106/* end of daemon_info.c */
void MHD_connection_cleanup_(struct MHD_Daemon *daemon)
functions to cleanup completed connection
#define CHECK_SIZE(type)
enum MHD_Bool MHD_daemon_get_information_sz(struct MHD_Daemon *daemon, enum MHD_DaemonInformationType info_type, union MHD_DaemonInformation *return_value, size_t return_value_size)
Definition daemon_info.c:45
MHD internal shared structures.
int MHD_socket
Definition microhttpd.h:207
@ MHD_YES
Definition microhttpd.h:167
@ MHD_NO
Definition microhttpd.h:162
uint16_t listen_port
Definition internal.h:1449
unsigned int worker_pool_size
Definition internal.h:1366
unsigned int connections
Definition internal.h:1361
struct MHD_Daemon * worker_pool
Definition internal.h:1073
MHD_socket listen_socket
Definition internal.h:1377
enum MHD_ThreadingMode threading_mode
Definition internal.h:1417