GNU libmicrohttpd
0.9.66
|
A minimal-HTTP server library. More...
#include "platform.h"
#include "internal.h"
#include "response.h"
#include "connection.h"
#include "memorypool.h"
#include "mhd_limits.h"
#include "autoinit_funcs.h"
#include "mhd_mono_clock.h"
#include "mhd_sockets.h"
#include "mhd_itc.h"
#include "mhd_compat.h"
#include "tsearch.h"
Go to the source code of this file.
Macros | |
#define | MHD_MAX_CONNECTIONS_DEFAULT (FD_SETSIZE - 4) |
#define | MHD_POOL_SIZE_DEFAULT (32 * 1024) |
#define | DEBUG_CLOSE MHD_NO |
#define | DEBUG_CONNECT MHD_NO |
Typedefs | |
typedef void(* | VfprintfFunctionPointerType) (void *cls, const char *format, va_list va) |
Functions | |
static void | close_all_connections (struct MHD_Daemon *daemon) |
static void | mhd_panic_std (void *cls, const char *file, unsigned int line, const char *reason) |
void | MHD_init (void) |
void | MHD_check_global_init_ (void) |
static void | MHD_default_logger_ (void *cls, const char *fm, va_list ap) |
_MHD_EXTERN void | MHD_free (void *ptr) |
static struct MHD_Daemon * | MHD_get_master (struct MHD_Daemon *daemon) |
static void | MHD_ip_count_lock (struct MHD_Daemon *daemon) |
static void | MHD_ip_count_unlock (struct MHD_Daemon *daemon) |
static int | MHD_ip_addr_compare (const void *a1, const void *a2) |
static int | MHD_ip_addr_to_key (const struct sockaddr *addr, socklen_t addrlen, struct MHD_IPCount *key) |
static int | MHD_ip_limit_add (struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen) |
static void | MHD_ip_limit_del (struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen) |
_MHD_EXTERN 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) |
_MHD_EXTERN 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) |
static int | call_handlers (struct MHD_Connection *con, bool read_ready, bool write_ready, bool force_close) |
static void | MHD_cleanup_connections (struct MHD_Daemon *daemon) |
static int | internal_add_connection (struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen, bool external_add, bool non_blck) |
void | internal_suspend_connection_ (struct MHD_Connection *connection) |
void | MHD_suspend_connection (struct MHD_Connection *connection) |
void | MHD_resume_connection (struct MHD_Connection *connection) |
static int | resume_suspended_connections (struct MHD_Daemon *daemon) |
_MHD_EXTERN int | MHD_add_connection (struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen) |
static int | MHD_accept_connection (struct MHD_Daemon *daemon) |
_MHD_EXTERN 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) |
_MHD_EXTERN 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) |
static int | MHD_select (struct MHD_Daemon *daemon, int may_block) |
static int | MHD_poll (struct MHD_Daemon *daemon, int may_block) |
_MHD_EXTERN int | MHD_run (struct MHD_Daemon *daemon) |
static void | close_connection (struct MHD_Connection *pos) |
static size_t | unescape_wrapper (void *cls, struct MHD_Connection *connection, char *val) |
_MHD_EXTERN struct MHD_Daemon * | MHD_start_daemon (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...) |
_MHD_EXTERN MHD_socket | MHD_quiesce_daemon (struct MHD_Daemon *daemon) |
static int | parse_options_va (struct MHD_Daemon *daemon, const struct sockaddr **servaddr, va_list ap) |
static int | parse_options (struct MHD_Daemon *daemon, const struct sockaddr **servaddr,...) |
_MHD_EXTERN 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) |
_MHD_EXTERN void | MHD_stop_daemon (struct MHD_Daemon *daemon) |
_MHD_EXTERN const union MHD_DaemonInfo * | MHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType info_type,...) |
_MHD_EXTERN void | MHD_set_panic_func (MHD_PanicCallback cb, void *cls) |
_MHD_EXTERN const char * | MHD_get_version (void) |
_MHD_EXTERN int | MHD_is_feature_supported (enum MHD_FEATURE feature) |
void | MHD_fini (void) |
Variables | |
MHD_PanicCallback | mhd_panic = NULL |
void * | mhd_panic_cls = NULL |
volatile int | global_init_count = 0 |
A minimal-HTTP server library.
Definition in file daemon.c.
#define DEBUG_CLOSE MHD_NO |
#define DEBUG_CONNECT MHD_NO |
#define MHD_MAX_CONNECTIONS_DEFAULT (FD_SETSIZE - 4) |
#define MHD_POOL_SIZE_DEFAULT (32 * 1024) |
typedef void(* VfprintfFunctionPointerType) (void *cls, const char *format, va_list va) |
|
static |
Call the handlers for a connection in the appropriate order based on the readiness as detected by the event loop.
con | connection to handle |
read_ready | set if the socket is ready for reading |
write_ready | set if the socket is ready for writing |
force_close | set if a hard error was detected on the socket; if this information is not available, simply pass MHD_NO |
Definition at line 1186 of file daemon.c.
References MHD_Connection::daemon, MHD_Daemon::data_already_pending, MHD_Connection::event_loop_info, MHD_CONNECTION_CHUNKED_BODY_READY, MHD_connection_close_(), MHD_connection_handle_idle(), MHD_connection_handle_read(), MHD_connection_handle_write(), MHD_CONNECTION_HEADERS_SENDING, MHD_CONNECTION_INIT, MHD_CONNECTION_NORMAL_BODY_READY, MHD_EVENT_LOOP_INFO_BLOCK, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::options, MHD_Connection::sk_nonblck, MHD_Connection::state, and MHD_Connection::tls_read_ready.
Referenced by internal_run_from_select().
|
static |
Close all connections for the daemon. Must only be called when MHD_Daemon::shutdown was set to MHD_YES.
daemon | daemon to close down |
Close all connections for the daemon. Must only be called when MHD_Daemon::shutdown was set to true.
daemon | daemon to close down |
Definition at line 6544 of file daemon.c.
References _, MHD_Daemon::cleanup_connection_mutex, close_connection(), MHD_Daemon::connections_tail, MHD_Connection::daemon, MHD_Daemon::itc, MHD_ALLOW_UPGRADE, mhd_assert, MHD_cleanup_connections(), MHD_connection_finish_forward_(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_resume_connection(), MHD_TEST_ALLOW_SUSPEND_RESUME, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::prev, resume_suspended_connections(), MHD_Connection::resuming, MHD_Daemon::resuming, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Daemon::suspended_connections_head, MHD_Daemon::suspended_connections_tail, MHD_Connection::thread_joined, and MHD_Daemon::worker_pool.
Referenced by MHD_stop_daemon().
|
static |
Close the given connection, remove it from all of its DLLs and move it into the cleanup queue.
pos | connection to move to cleanup |
Definition at line 4639 of file daemon.c.
References MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::cleanup_head, MHD_Daemon::cleanup_tail, MHD_Connection::connection_timeout, MHD_Daemon::connection_timeout, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, MHD_Daemon::manual_timeout_head, MHD_Daemon::manual_timeout_tail, mhd_assert, MHD_connection_close_(), MHD_connection_mark_closed_(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, MHD_Daemon::options, MHD_Connection::resuming, MHD_Connection::suspended, and XDLL_remove.
Referenced by close_all_connections().
|
static |
Add another client connection to the set of connections managed by MHD. This API is usually not needed (since MHD will accept inbound connections on the server socket). Use this API in special cases, for example if your HTTP server is behind NAT and needs to connect out to the HTTP client.
The given client socket will be managed (and closed!) by MHD after this call and must no longer be used directly by the application afterwards.
daemon | daemon that manages the connection |
client_socket | socket to manage (MHD will expect to receive an HTTP request from this socket next). |
addr | IP address of the client |
addrlen | number of bytes in addr |
external_add | perform additional operations needed due to the application calling us directly |
non_blck | indicate that socket in non-blocking mode |
Definition at line 2346 of file daemon.c.
References _, MHD_Connection::addr, MHD_Connection::addr_len, MHD_Daemon::apc, MHD_Daemon::apc_cls, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::connection_limit, MHD_Connection::connection_timeout, MHD_Daemon::connection_timeout, MHD_Daemon::connections, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, EDLL_insert, MHD_Daemon::itc, MHD_Connection::last_activity, mhd_assert, MHD_calloc_(), MHD_CONNECTION_NOTIFY_CLOSED, MHD_CONNECTION_NOTIFY_STARTED, MHD_create_named_thread_, MHD_EPOLL_STATE_IN_EPOLL_SET, MHD_EPOLL_STATE_IN_EREADY_EDLL, MHD_EPOLL_STATE_READ_READY, MHD_EPOLL_STATE_WRITE_READY, MHD_ip_limit_add(), MHD_ip_limit_del(), MHD_monotonic_sec_counter(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_PANIC, MHD_pool_create(), MHD_pool_destroy(), MHD_SCKT_FD_FITS_FDSET_, MHD_set_http_callbacks_(), MHD_set_https_callbacks(), MHD_socket_close_chk_, MHD_socket_last_strerr_, MHD_strerror_, MHD_TLS_CONN_INIT, MHD_USE_EPOLL, MHD_USE_INSECURE_TLS_EARLY_DATA, MHD_USE_POLL, MHD_USE_POST_HANDSHAKE_AUTH_SUPPORT, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_USE_TURBO, MHD_YES, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, MHD_Daemon::notify_connection, MHD_Daemon::notify_connection_cls, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Daemon::pid, MHD_Connection::pool, MHD_Daemon::pool_size, MHD_Connection::sk_nonblck, MHD_Connection::socket_context, MHD_Connection::socket_fd, thread_main_handle_connection(), MHD_Daemon::worker_pool, MHD_Daemon::worker_pool_size, XDLL_insert, and XDLL_remove.
Referenced by MHD_accept_connection(), and MHD_add_connection().
|
static |
Internal version of MHD_get_fdset2().
daemon | daemon to get sets from |
read_fd_set | read set |
write_fd_set | write set |
except_fd_set | except set |
max_fd | increased to largest FD added (if larger than existing value); can be NULL |
fd_setsize | value of FD_SETSIZE |
Definition at line 971 of file daemon.c.
References _, MHD_Daemon::connections_tail, MHD_Connection::daemon, 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().
|
static |
Internal version of MHD_run_from_select().
daemon | daemon to run select loop for |
read_fd_set | read set |
write_fd_set | write set |
except_fd_set | except set (not used, can be NULL) |
Definition at line 3474 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().
void internal_suspend_connection_ | ( | struct MHD_Connection * | connection | ) |
Internal version of MHD_suspend_connection().
connection | the connection to suspend |
Definition at line 2772 of file daemon.c.
References _, MHD_Daemon::cleanup_connection_mutex, MHD_Connection::connection_timeout, MHD_Daemon::connection_timeout, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, EDLL_remove, MHD_Daemon::manual_timeout_head, MHD_Daemon::manual_timeout_tail, mhd_assert, MHD_EPOLL_STATE_IN_EPOLL_SET, MHD_EPOLL_STATE_IN_EREADY_EDLL, MHD_EPOLL_STATE_SUSPENDED, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_USE_EPOLL, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, NULL, MHD_Daemon::options, MHD_Connection::resuming, MHD_Connection::socket_fd, MHD_Connection::suspended, MHD_Daemon::suspended_connections_head, MHD_Daemon::suspended_connections_tail, and XDLL_remove.
Referenced by MHD_suspend_connection().
|
static |
Accept an incoming connection and create the MHD_Connection object for it. This function also enforces policy by way of checking with the accept policy callback.
daemon | handle with the listen socket |
Definition at line 3143 of file daemon.c.
References _, MHD_Daemon::at_limit, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::connections, fd, internal_add_connection(), MHD_Daemon::listen_fd, MAYBE_SOCK_CLOEXEC, MAYBE_SOCK_NONBLOCK, MAYBE_SOCK_NOSIGPIPE, MHD_INVALID_SOCKET, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_SCKT_EINVAL_, MHD_SCKT_ERR_IS_, MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_, MHD_SCKT_ERR_IS_EAGAIN_, MHD_SCKT_ERR_IS_LOW_RESOURCES_, MHD_socket_close_chk_, MHD_socket_get_error_, MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_socket_noninheritable_(), MHD_socket_strerr_, MHD_YES, and MHD_Daemon::was_quiesced.
Referenced by internal_run_from_select().
void MHD_check_global_init_ | ( | void | ) |
Check whether global initialisation was performed and call initialiser if necessary.
Definition at line 204 of file daemon.c.
References global_init_count, MHD_init(), MHD_mutex_lock_chk_, and MHD_mutex_unlock_chk_.
Referenced by MHD_start_daemon_va().
|
static |
Free resources associated with all closed connections. (destroy responses, free buffers, etc.). All closed connections are kept in the "cleanup" doubly-linked list.
daemon | daemon to clean up |
Free resources associated with all closed connections. (destroy responses, free buffers, etc.). All closed connections are kept in the "cleanup" doubly-linked list.
daemon | daemon to clean up |
Definition at line 3275 of file daemon.c.
References _, MHD_Connection::addr, MHD_Connection::addr_len, MHD_Daemon::at_limit, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::cleanup_head, MHD_Daemon::cleanup_tail, MHD_Daemon::connections, MHD_Connection::daemon, DLL_remove, EDLL_remove, MHD_CONNECTION_NOTIFY_CLOSED, MHD_destroy_response(), MHD_EPOLL_STATE_IN_EPOLL_SET, MHD_EPOLL_STATE_IN_EREADY_EDLL, MHD_INVALID_SOCKET, MHD_ip_limit_del(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_pool_destroy(), MHD_socket_close_chk_, MHD_USE_EPOLL, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::notify_connection, MHD_Daemon::notify_connection_cls, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::pool, MHD_Connection::response, MHD_Connection::socket_context, MHD_Connection::socket_fd, and MHD_Connection::thread_joined.
Referenced by close_all_connections(), internal_run_from_select(), MHD_get_daemon_info(), MHD_run(), and MHD_run_from_select().
|
static |
Default logger function
Definition at line 226 of file daemon.c.
Referenced by MHD_start_daemon_va().
void MHD_fini | ( | void | ) |
Definition at line 7237 of file daemon.c.
References MHD_monotonic_sec_counter_finish().
_MHD_EXTERN void MHD_free | ( | void * | ptr | ) |
Free the memory given by ptr. Calls "free(ptr)". This function should be used to free the username returned by MHD_digest_auth_get_username().
ptr | pointer to free. |
|
static |
Trace up to and return master daemon. If the supplied daemon is a master, then return the daemon itself.
daemon | handle to a daemon |
Definition at line 260 of file daemon.c.
References MHD_Daemon::master, and NULL.
Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().
void MHD_init | ( | void | ) |
Globally initialise library.
Initialize do setup work.
Definition at line 7192 of file daemon.c.
References _, MHD_init_mem_pools_(), MHD_monotonic_sec_counter_init(), MHD_PANIC, mhd_panic, mhd_panic_std(), and NULL.
Referenced by MHD_check_global_init_().
|
static |
Tree comparison function for IP addresses (supplied to tsearch() family). We compare everything in the struct up through the beginning of the 'count' field.
a1 | first address to compare |
a2 | second address to compare |
Definition at line 344 of file daemon.c.
Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().
|
static |
Parse address and initialize key using the address.
addr | address to parse |
addrlen | number of bytes in addr |
key | where to store the parsed address |
Definition at line 363 of file daemon.c.
References MHD_NO, and MHD_YES.
Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().
|
static |
Lock shared structure for IP connection counts and connection DLLs.
daemon | handle to daemon where lock is |
Definition at line 308 of file daemon.c.
References MHD_mutex_lock_chk_, and MHD_Daemon::per_ip_connection_mutex.
Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().
|
static |
Unlock shared structure for IP connection counts and connection DLLs.
daemon | handle to daemon where lock is |
Definition at line 324 of file daemon.c.
References MHD_mutex_unlock_chk_, and MHD_Daemon::per_ip_connection_mutex.
Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().
|
static |
Check if IP address is over its limit in terms of the number of allowed concurrent connections. If the IP is still allowed, increments the connection counter.
daemon | handle to daemon where connection counts are tracked |
addr | address to add (or increment counter) |
addrlen | number of bytes in addr |
Definition at line 414 of file daemon.c.
References _, MHD_get_master(), MHD_ip_addr_compare(), MHD_ip_addr_to_key(), MHD_ip_count_lock(), MHD_ip_count_unlock(), MHD_NO, MHD_YES, NULL, MHD_Daemon::per_ip_connection_count, MHD_Daemon::per_ip_connection_limit, and tsearch().
Referenced by internal_add_connection().
|
static |
Decrement connection count for IP address, removing from table count reaches 0.
daemon | handle to daemon where connection counts are tracked |
addr | address to remove (or decrement counter) |
addrlen | number of bytes in addr |
Definition at line 480 of file daemon.c.
References _, MHD_get_master(), MHD_ip_addr_compare(), MHD_ip_addr_to_key(), MHD_ip_count_lock(), MHD_ip_count_unlock(), MHD_NO, MHD_PANIC, NULL, MHD_Daemon::per_ip_connection_count, MHD_Daemon::per_ip_connection_limit, tdelete(), and tfind().
Referenced by internal_add_connection(), and MHD_cleanup_connections().
|
static |
Default implementation of the panic function, prints an error message and aborts.
cls | unused |
file | name of the file with the problem |
line | line number with the problem |
reason | error message with details |
Definition at line 132 of file daemon.c.
References _.
Referenced by MHD_init().
|
static |
Do poll()-based processing.
Definition at line 4094 of file daemon.c.
References MHD_NO, MHD_USE_THREAD_PER_CONNECTION, MHD_Daemon::options, and MHD_Daemon::shutdown.
Referenced by MHD_run().
void MHD_resume_connection | ( | struct MHD_Connection * | connection | ) |
Resume handling of network data for suspended connection. It is safe to resume a suspended connection at any time. Calling this function on a connection that was not previously suspended will result in undefined behavior.
connection | the connection to resume |
Definition at line 2896 of file daemon.c.
References _, MHD_Daemon::cleanup_connection_mutex, MHD_Connection::daemon, MHD_Daemon::itc, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_TEST_ALLOW_SUSPEND_RESUME, MHD_Daemon::options, MHD_Connection::resuming, and MHD_Daemon::resuming.
Referenced by close_all_connections(), and internal_run_from_select().
|
static |
Main internal select() call. Will compute select sets, call select() and then internal_run_from_select with the result.
daemon | daemon to run select() loop for |
may_block | MHD_YES if blocking, MHD_NO if non-blocking |
Definition at line 3632 of file daemon.c.
References _, MHD_Daemon::at_limit, MHD_Daemon::connection_limit, MHD_Daemon::connections, internal_get_fdset2(), internal_run_from_select(), MHD_Daemon::itc, MHD_Daemon::listen_fd, MHD_add_to_fd_set_(), MHD_get_timeout(), MHD_INVALID_SOCKET, MHD_NO, MHD_SCKT_ERR_IS_EINTR_, MHD_socket_get_error_, MHD_socket_strerr_, MHD_SYS_select_, MHD_TEST_ALLOW_SUSPEND_RESUME, MHD_UNSIGNED_LONG_LONG, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, NULL, MHD_Daemon::options, resume_suspended_connections(), MHD_Daemon::shutdown, TIMEVAL_TV_SEC_MAX, and MHD_Daemon::was_quiesced.
Referenced by MHD_run().
void MHD_suspend_connection | ( | struct MHD_Connection * | connection | ) |
Suspend handling of network data for a given connection. This can be used to dequeue a connection from MHD's event loop (external select, internal select or thread pool; not applicable to thread-per-connection!) for a while.
If you use this API in conjunction with a internal select or a thread pool, you must set the option MHD_USE_ITC to ensure that a resumed connection is immediately processed by MHD.
Suspended connections continue to count against the total number of connections allowed (per daemon, as well as per IP, if such limits are set). Suspended connections will NOT time out; timeouts will restart when the connection handling is resumed. While a connection is suspended, MHD will not detect disconnects by the client.
The only safe time to suspend a connection is from the MHD_AccessHandlerCallback.
Finally, it is an API violation to call MHD_stop_daemon while having suspended connections (this will at least create memory and socket leaks or lead to undefined behavior). You must explicitly resume all connections before stopping the daemon.
connection | the connection to suspend |
Definition at line 2867 of file daemon.c.
References _, MHD_Connection::daemon, internal_suspend_connection_(), MHD_PANIC, MHD_TEST_ALLOW_SUSPEND_RESUME, NULL, and MHD_Daemon::options.
|
static |
Parse a list of options given as varargs.
daemon | the daemon to initialize |
servaddr | where to store the server's listen address |
... | the options |
Definition at line 4908 of file daemon.c.
References parse_options_va().
Referenced by parse_options_va().
|
static |
Parse a list of options given as varargs.
daemon | the daemon to initialize |
servaddr | where to store the server's listen address |
ap | the options |
Definition at line 4933 of file daemon.c.
References _, MHD_Daemon::connection_limit, MHD_Daemon::connection_timeout, MHD_Daemon::listen_backlog_size, MHD_Daemon::listen_fd, MHD_Daemon::listening_address_reuse, MHD_NO, MHD_OPTION_ARRAY, MHD_OPTION_CONNECTION_LIMIT, MHD_OPTION_CONNECTION_MEMORY_INCREMENT, MHD_OPTION_CONNECTION_MEMORY_LIMIT, MHD_OPTION_CONNECTION_TIMEOUT, MHD_OPTION_DIGEST_AUTH_RANDOM, MHD_OPTION_END, MHD_OPTION_EXTERNAL_LOGGER, MHD_OPTION_GNUTLS_PSK_CRED_HANDLER, MHD_OPTION_HTTPS_CERT_CALLBACK, MHD_OPTION_HTTPS_CERT_CALLBACK2, MHD_OPTION_HTTPS_CRED_TYPE, MHD_OPTION_HTTPS_KEY_PASSWORD, MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_DHPARAMS, MHD_OPTION_HTTPS_MEM_KEY, MHD_OPTION_HTTPS_MEM_TRUST, MHD_OPTION_HTTPS_PRIORITIES, MHD_OPTION_LISTEN_BACKLOG_SIZE, MHD_OPTION_LISTEN_SOCKET, MHD_OPTION_LISTENING_ADDRESS_REUSE, MHD_OPTION_NONCE_NC_SIZE, MHD_OPTION_NOTIFY_COMPLETED, MHD_OPTION_NOTIFY_CONNECTION, MHD_OPTION_PER_IP_CONNECTION_LIMIT, MHD_OPTION_SOCK_ADDR, MHD_OPTION_STRICT_FOR_CLIENT, MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE, MHD_OPTION_THREAD_POOL_SIZE, MHD_OPTION_THREAD_STACK_SIZE, MHD_OPTION_UNESCAPE_CALLBACK, MHD_OPTION_URI_LOG_CALLBACK, MHD_TYPE_IS_SIGNED_, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_NO_LISTEN_SOCKET, MHD_USE_PEDANTIC_CHECKS, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_YES, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, MHD_Daemon::notify_connection, MHD_Daemon::notify_connection_cls, NULL, MHD_OptionItem::option, MHD_Daemon::options, parse_options(), MHD_Daemon::per_ip_connection_limit, MHD_Daemon::pool_increment, MHD_Daemon::pool_size, MHD_OptionItem::ptr_value, SIZE_MAX, MHD_Daemon::strict_for_client, UINT_MAX, MHD_Daemon::unescape_callback, MHD_Daemon::unescape_callback_cls, MHD_Daemon::uri_log_callback, MHD_Daemon::uri_log_callback_cls, MHD_OptionItem::value, and MHD_Daemon::worker_pool_size.
Referenced by MHD_start_daemon_va(), and parse_options().
|
static |
Run through the suspended connections and move any that are no longer suspended back to the active state.
daemon | daemon context |
Definition at line 2931 of file daemon.c.
References _, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::cleanup_head, MHD_Daemon::cleanup_tail, MHD_Connection::client_aware, MHD_Connection::client_context, MHD_Connection::connection_timeout, MHD_Daemon::connection_timeout, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, EDLL_insert, MHD_Daemon::itc, MHD_Connection::last_activity, MHD_Daemon::manual_timeout_head, MHD_Daemon::manual_timeout_tail, mhd_assert, MHD_EPOLL_STATE_IN_EREADY_EDLL, MHD_EPOLL_STATE_SUSPENDED, MHD_EPOLL_STATE_WRITE_READY, MHD_monotonic_sec_counter(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_PANIC, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_USE_EPOLL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, NULL, MHD_Daemon::options, MHD_Connection::prev, MHD_Connection::resuming, MHD_Daemon::resuming, MHD_Daemon::shutdown, MHD_Connection::suspended, MHD_Daemon::suspended_connections_head, MHD_Daemon::suspended_connections_tail, MHD_Daemon::worker_pool, and XDLL_insert.
Referenced by close_all_connections(), MHD_run_from_select(), and MHD_select().
|
static |
Process escape sequences ('HH') Updates val in place; the result should be UTF-8 encoded and cannot be larger than the input. The result must also still be 0-terminated.
cls | closure (use NULL) |
connection | handle to connection, not used |
val | value to unescape (modified in the process) |
Definition at line 4726 of file daemon.c.
References MHD_http_unescape().
Referenced by MHD_start_daemon_va().
volatile int global_init_count = 0 |
Track global initialisation
Definition at line 187 of file daemon.c.
Referenced by MHD_check_global_init_().
MHD_PanicCallback mhd_panic = NULL |
Handler for fatal errors.
Definition at line 156 of file daemon.c.
Referenced by build_header_response(), MHD_create_post_processor(), MHD_init(), post_process_multipart(), post_process_urlencoded(), and process_request_body().
void* mhd_panic_cls = NULL |
Closure argument for mhd_panic.
Definition at line 161 of file daemon.c.
Referenced by build_header_response(), MHD_create_post_processor(), post_process_multipart(), post_process_urlencoded(), and process_request_body().