GNU libmicrohttpd  0.9.70
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 
44 enum 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
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
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
87  }
88  }
89  else
90  return_value->num_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 */
MHD_socket
int MHD_socket
Definition: microhttpd.h:187
MHD_Daemon::worker_pool
struct MHD_Daemon * worker_pool
Definition: internal.h:1073
MHD_Daemon::worker_pool_size
unsigned int worker_pool_size
Definition: internal.h:1366
MHD_YES
#define MHD_YES
Definition: microhttpd.h:140
MHD_Daemon::connections
unsigned int connections
Definition: internal.h:1361
internal.h
internal shared structures
CHECK_SIZE
#define CHECK_SIZE(type)
MHD_Daemon::threading_mode
enum MHD_ThreadingMode threading_mode
Definition: internal.h:1417
MHD_Daemon::listen_port
uint16_t listen_port
Definition: internal.h:1449
connection_cleanup.h
functions to cleanup completed connection
MHD_Daemon
Definition: internal.h:1000
MHD_connection_cleanup_
void MHD_connection_cleanup_(struct MHD_Daemon *daemon)
Definition: connection_cleanup.c:78
MHD_Connection::daemon
struct MHD_Daemon * daemon
Definition: internal.h:675
MHD_Daemon::listen_socket
MHD_socket listen_socket
Definition: internal.h:1377
MHD_daemon_get_information_sz
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_NO
#define MHD_NO
Definition: microhttpd.h:145