GNU libmicrohttpd  0.9.29
event-loop control

Functions

_MHD_EXTERN struct MHD_DaemonMHD_start_daemon_va (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
 
_MHD_EXTERN struct MHD_DaemonMHD_start_daemon (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
 
_MHD_EXTERN void MHD_stop_daemon (struct MHD_Daemon *daemon)
 
int MHD_get_fdset (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd)
 
static int internal_get_fdset2 (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
 
int MHD_get_fdset2 (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
 
int MHD_get_timeout (struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
 
static int internal_run_from_select (struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
 
int MHD_run_from_select (struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
 
int MHD_run (struct MHD_Daemon *daemon)
 

Detailed Description

MHD API to start and stop the HTTP server and manage the event loop.

Function Documentation

◆ internal_get_fdset2()

static int internal_get_fdset2 ( struct MHD_Daemon daemon,
fd_set *  read_fd_set,
fd_set *  write_fd_set,
fd_set *  except_fd_set,
MHD_socket max_fd,
unsigned int  fd_setsize 
)
static

Internal version of MHD_get_fdset2().

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
fd_setsizevalue of FD_SETSIZE
Returns
MHD_YES on success, MHD_NO if any FD didn't fit fd_set.

Definition at line 927 of file daemon.c.

References _, MHD_Daemon::connections_tail, MHD_Connection::event_loop_info, MHD_Daemon::listen_fd, MHD_add_to_fd_set_(), MHD_EVENT_LOOP_INFO_BLOCK, MHD_EVENT_LOOP_INFO_CLEANUP, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_INVALID_SOCKET, MHD_NO, MHD_YES, NULL, MHD_Connection::prev, MHD_Daemon::shutdown, MHD_Connection::socket_fd, and MHD_Daemon::was_quiesced.

Referenced by MHD_get_fdset2(), and MHD_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_run_from_select()

static int internal_run_from_select ( struct MHD_Daemon daemon,
const fd_set *  read_fd_set,
const fd_set *  write_fd_set,
const fd_set *  except_fd_set 
)
static

Internal version of MHD_run_from_select().

Parameters
daemondaemon to run select loop for
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set (not used, can be NULL)
Returns
MHD_NO on serious errors, MHD_YES on success

Definition at line 3359 of file daemon.c.

References call_handlers(), MHD_Daemon::connections_tail, MHD_Daemon::data_already_pending, MHD_Daemon::itc, MHD_Daemon::listen_fd, MHD_accept_connection(), MHD_cleanup_connections(), MHD_connection_finish_forward_, MHD_INVALID_SOCKET, MHD_resume_connection(), MHD_USE_THREAD_PER_CONNECTION, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::prev, MHD_Connection::socket_fd, and MHD_Daemon::was_quiesced.

Referenced by MHD_run_from_select(), and MHD_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_get_fdset()

int MHD_get_fdset ( struct MHD_Daemon daemon,
fd_set *  read_fd_set,
fd_set *  write_fd_set,
fd_set *  except_fd_set,
MHD_socket max_fd 
)

Obtain the select() sets for this daemon. Daemon's FDs will be added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO for each fd_set before calling this function. FD_SETSIZE is assumed to be platform's default.

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or any FD didn't fit fd_set.

Definition at line 678 of file daemon.c.

References _MHD_SYS_DEFAULT_FD_SETSIZE, MHD_add_to_fd_set_(), MHD_EPOLL_STATE_ERROR, MHD_EPOLL_STATE_READ_READY, MHD_EPOLL_STATE_WRITE_READY, MHD_get_fdset2(), and MHD_INVALID_SOCKET.

Here is the call graph for this function:

◆ MHD_get_fdset2()

int MHD_get_fdset2 ( struct MHD_Daemon daemon,
fd_set *  read_fd_set,
fd_set *  write_fd_set,
fd_set *  except_fd_set,
MHD_socket max_fd,
unsigned int  fd_setsize 
)

Obtain the select() sets for this daemon. Daemon's FDs will be added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO for each fd_set before calling this function. Passing custom FD_SETSIZE as fd_setsize allow usage of larger/smaller than platform's default fd_sets.

This function must be called only for daemon started without MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemondaemon to get sets from
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
max_fdincreased to largest FD added (if larger than existing value); can be NULL
fd_setsizevalue of FD_SETSIZE
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call or any FD didn't fit fd_set.

Definition at line 1068 of file daemon.c.

References _, internal_get_fdset2(), MHD_add_to_fd_set_(), MHD_NO, MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_POLL, MHD_YES, NULL, MHD_Daemon::options, and MHD_Daemon::shutdown.

Referenced by MHD_get_fdset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_get_timeout()

int MHD_get_timeout ( struct MHD_Daemon daemon,
MHD_UNSIGNED_LONG_LONG timeout 
)

Obtain timeout value for select() for this daemon (only needed if connection timeout is used). The returned value is how long select() or poll() should at most block, not the timeout value set for connections. This function MUST NOT be called if MHD is running with MHD_USE_THREAD_PER_CONNECTION.

Remarks
To be called only from thread that process daemon's select()/poll()/etc.
Parameters
daemondaemon to query for timeout
timeoutset to the timeout (in milliseconds)
Returns
MHD_YES on success, MHD_NO if timeouts are not used (or no connections exist that would necessitate the use of a timeout right now).

Definition at line 3270 of file daemon.c.

References _, MHD_Connection::connection_timeout, MHD_Daemon::data_already_pending, MHD_Connection::last_activity, MHD_Daemon::manual_timeout_tail, MHD_monotonic_sec_counter(), MHD_NO, MHD_USE_EPOLL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Daemon::normal_timeout_tail, NULL, MHD_Daemon::options, MHD_Connection::prevX, and ULLONG_MAX.

Referenced by MHD_poll(), and MHD_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_run()

int MHD_run ( struct MHD_Daemon daemon)

Run webserver operations (without blocking unless in client callbacks). This method should be called by clients in combination with MHD_get_fdset if the client-controlled select method is used.

This function is a convenience method, which is useful if the fd_sets from MHD_get_fdset were not directly passed to select(); with this function, MHD will internally do the appropriate select() call itself again. While it is always safe to call MHD_run (in external select mode), you should call MHD_run_from_select if performance is important (as it saves an expensive call to select()).

Parameters
daemondaemon to run
Returns
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call.

Definition at line 4481 of file daemon.c.

References MHD_cleanup_connections(), MHD_NO, MHD_poll(), MHD_select(), MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_POLL, MHD_YES, MHD_Daemon::options, and MHD_Daemon::shutdown.

Here is the call graph for this function:

◆ MHD_run_from_select()

int MHD_run_from_select ( struct MHD_Daemon daemon,
const fd_set *  read_fd_set,
const fd_set *  write_fd_set,
const fd_set *  except_fd_set 
)

Run webserver operations. This method should be called by clients in combination with MHD_get_fdset if the client-controlled select method is used.

You can use this function instead of MHD_run if you called select() on the result from MHD_get_fdset. File descriptors in the sets that are not controlled by MHD will be ignored. Calling this function instead of MHD_run is more efficient as MHD will not have to call select() again to determine which operations are ready.

This function cannot be used with daemon started with MHD_USE_INTERNAL_POLLING_THREAD flag.

Parameters
daemondaemon to run select loop for
read_fd_setread set
write_fd_setwrite set
except_fd_setexcept set
Returns
MHD_NO on serious errors, MHD_YES on success

Definition at line 3463 of file daemon.c.

References _, internal_run_from_select(), MHD_cleanup_connections(), MHD_NO, MHD_TEST_ALLOW_SUSPEND_RESUME, MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_POLL, NULL, MHD_Daemon::options, and resume_suspended_connections().

Here is the call graph for this function:

◆ MHD_start_daemon()

struct MHD_Daemon * MHD_start_daemon ( unsigned int  flags,
uint16_t  port,
MHD_AcceptPolicyCallback  apc,
void *  apc_cls,
MHD_AccessHandlerCallback  dh,
void *  dh_cls,
  ... 
)

Start a webserver on the given port. Variadic version of MHD_start_daemon_va.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
Returns
NULL on error, handle to daemon on success

Start a webserver on the given port. Variadic version of MHD_start_daemon_va.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
Returns
NULL on error, handle to daemon on success

Definition at line 4622 of file daemon.c.

References MHD_start_daemon_va().

Here is the call graph for this function:

◆ MHD_start_daemon_va()

struct MHD_Daemon * MHD_start_daemon_va ( unsigned int  flags,
uint16_t  port,
MHD_AcceptPolicyCallback  apc,
void *  apc_cls,
MHD_AccessHandlerCallback  dh,
void *  dh_cls,
va_list  ap 
)

Start a webserver on the given port.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to (in host byte order)
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
aplist of options (type-value pairs, terminated with MHD_OPTION_END).
Returns
NULL on error, handle to daemon on success

Start a webserver on the given port.

Parameters
flagscombination of enum MHD_FLAG values
portport to bind to (in host byte order)
apccallback to call to check which clients will be allowed to connect; you can pass NULL in which case connections from any IP will be accepted
apc_clsextra argument to apc
dhhandler called for all requests (repeatedly)
dh_clsextra argument to dh
aplist of options (type-value pairs, terminated with MHD_OPTION_END).
Returns
NULL on error, handle to daemon on success

Definition at line 5360 of file daemon.c.

References _, MHD_Daemon::apc, MHD_Daemon::apc_cls, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::connection_limit, MHD_Daemon::connection_timeout, MHD_Daemon::connections, MHD_Daemon::default_handler, MHD_Daemon::default_handler_cls, MHD_Daemon::itc, MHD_Daemon::listen_backlog_size, MHD_Daemon::listen_fd, MHD_Daemon::listening_address_reuse, MHD_Daemon::master, MHD_ALLOW_SUSPEND_RESUME, MHD_ALLOW_UPGRADE, MHD_BUF_INC_SIZE, MHD_calloc_(), MHD_create_named_thread_, MHD_INVALID_SOCKET, MHD_itc_destroy_chk_, MHD_MAX_CONNECTIONS_DEFAULT, MHD_mutex_destroy_chk_, MHD_PANIC, MHD_POOL_SIZE_DEFAULT, MHD_SCKT_FD_FITS_FDSET_, MHD_select_thread(), MHD_socket_close_chk_, MHD_socket_create_listen_(), MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_stop_daemon(), MHD_strerror_, MHD_USE_AUTO, MHD_USE_DUAL_STACK, MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_IPv6, MHD_USE_ITC, MHD_USE_NO_LISTEN_SOCKET, MHD_USE_PEDANTIC_CHECKS, MHD_USE_POLL, MHD_USE_TCP_FASTOPEN, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_YES, NULL, MHD_Daemon::options, parse_options_va(), MHD_Daemon::per_ip_connection_mutex, MHD_Daemon::pid, MHD_Daemon::pool_increment, MHD_Daemon::pool_size, MHD_Daemon::port, MHD_Daemon::strict_for_client, MHD_Daemon::thread_stack_size, MHD_Daemon::unescape_callback, unescape_wrapper(), MHD_Daemon::worker_pool, and MHD_Daemon::worker_pool_size.

Referenced by MHD_start_daemon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_stop_daemon()