daemon.c File Reference

A minimal-HTTP server library. More...

#include "platform.h"
#include "internal.h"
#include "response.h"
#include "connection.h"
#include "memorypool.h"
#include <limits.h>

Include dependency graph for daemon.c:

Go to the source code of this file.

Defines

#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
#define MSG_NOSIGNAL   0
#define SOCK_CLOEXEC   0
#define ATTRIBUTE_CONSTRUCTOR
#define ATTRIBUTE_DESTRUCTOR

Typedefs

typedef void(*) VfprintfFunctionPointerType (void *cls, const char *format, va_list va)

Functions

static void mhd_panic_std (void *cls, const char *file, unsigned int line, const char *reason)
static struct MHD_DaemonMHD_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)
int MHD_get_fdset (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, int *max_fd)
static void * MHD_handle_connection (void *data)
static ssize_t recv_param_adapter (struct MHD_Connection *connection, void *other, size_t i)
static ssize_t send_param_adapter (struct MHD_Connection *connection, const void *other, size_t i)
static int create_thread (pthread_t *thread, const struct MHD_Daemon *daemon, void *(*start_routine)(void *), void *arg)
int MHD_add_connection (struct MHD_Daemon *daemon, int client_socket, const struct sockaddr *addr, socklen_t addrlen)
static int MHD_accept_connection (struct MHD_Daemon *daemon)
static void MHD_cleanup_connections (struct MHD_Daemon *daemon)
int MHD_get_timeout (struct MHD_Daemon *daemon, unsigned MHD_LONG_LONG *timeout)
static int MHD_select (struct MHD_Daemon *daemon, int may_block)
static int MHD_poll (struct MHD_Daemon *daemon, int may_block)
int MHD_run (struct MHD_Daemon *daemon)
static void * MHD_select_thread (void *cls)
MHD_DaemonMHD_start_daemon (unsigned int options, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
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,...)
static int create_socket (int domain, int type, int protocol)
MHD_DaemonMHD_start_daemon_va (unsigned int options, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
static void close_all_connections (struct MHD_Daemon *daemon)
void MHD_stop_daemon (struct MHD_Daemon *daemon)
MHD_DaemonInfoMHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType infoType,...)
void MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
const char * MHD_get_version (void)
void ATTRIBUTE_CONSTRUCTOR MHD_init ()
void ATTRIBUTE_DESTRUCTOR MHD_fini ()

Variables

MHD_PanicCallback mhd_panic
void * mhd_panic_cls


Detailed Description

A minimal-HTTP server library.

Author:
Daniel Pittman

Christian Grothoff

Definition in file daemon.c.


Define Documentation

#define ATTRIBUTE_CONSTRUCTOR

Definition at line 2776 of file daemon.c.

#define ATTRIBUTE_DESTRUCTOR

Definition at line 2777 of file daemon.c.

#define DEBUG_CLOSE   MHD_NO

Print extra messages with reasons for closing sockets? (only adds non-error messages).

Definition at line 66 of file daemon.c.

#define DEBUG_CONNECT   MHD_NO

Print extra messages when establishing connections? (only adds non-error messages).

Definition at line 72 of file daemon.c.

#define MHD_MAX_CONNECTIONS_DEFAULT   FD_SETSIZE - 4

Default connection limit.

Definition at line 52 of file daemon.c.

Referenced by MHD_start_daemon_va().

#define MHD_POOL_SIZE_DEFAULT   (32 * 1024)

Default memory allowed per connection.

Definition at line 60 of file daemon.c.

Referenced by MHD_start_daemon_va().

#define MSG_NOSIGNAL   0

Definition at line 76 of file daemon.c.

Referenced by recv_param_adapter(), and send_param_adapter().

#define SOCK_CLOEXEC   0

Definition at line 81 of file daemon.c.

Referenced by create_socket(), and MHD_accept_connection().


Typedef Documentation

typedef void(*) VfprintfFunctionPointerType(void *cls, const char *format, va_list va)

Signature of the MHD custom logger function.

Parameters:
cls closure
format format string
va arguments to the format string (fprintf-style)

Definition at line 1688 of file daemon.c.


Function Documentation

static void close_all_connections ( struct MHD_Daemon daemon  )  [static]

Close all connections for the daemon; must only be called after all of the threads have been joined and there is no more concurrent activity on the connection lists.

Parameters:
daemon daemon to close down

Definition at line 2559 of file daemon.c.

References MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::cleanup_head, MHD_Daemon::cleanup_tail, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, MHD_cleanup_connections(), MHD_connection_close(), MHD_PANIC, MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::read_closed, SHUTDOWN, MHD_Connection::socket_fd, and MHD_Connection::thread_joined.

Here is the call graph for this function:

static int create_socket ( int  domain,
int  type,
int  protocol 
) [static]

Create a listen socket, if possible with CLOEXEC flag set.

Parameters:
domain socket domain (i.e. PF_INET)
type socket type (usually SOCK_STREAM)
protocol desired protocol, 0 for default

Definition at line 1991 of file daemon.c.

References SOCK_CLOEXEC, and SOCKET.

Referenced by MHD_start_daemon_va().

Here is the caller graph for this function:

static int create_thread ( pthread_t *  thread,
const struct MHD_Daemon daemon,
void *(*)(void *)  start_routine,
void *  arg 
) [static]

Create a thread and set the attributes according to our options.

Parameters:
thread handle to initialize
daemon daemon with options
start_routine main function of thread
arg argument for start_routine
Returns:
0 on success

Definition at line 792 of file daemon.c.

References NULL, and MHD_Daemon::thread_stack_size.

Referenced by MHD_add_connection(), and MHD_start_daemon_va().

Here is the caller graph for this function:

static int MHD_accept_connection ( struct MHD_Daemon daemon  )  [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.

Parameters:
daemon handle with the listen socket
Returns:
MHD_YES on success

Definition at line 1105 of file daemon.c.

References ACCEPT, CLOSE, MHD_add_connection(), MHD_NO, MHD_YES, SHUTDOWN, SOCK_CLOEXEC, MHD_Daemon::socket_fd, and STRERROR.

Referenced by MHD_select().

Here is the call graph for this function:

Here is the caller graph for this function:

int MHD_add_connection ( struct MHD_Daemon daemon,
int  client_socket,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

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.

Per-IP connection limits are ignored when using this API.

Parameters:
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
Returns:
MHD_YES on success, MHD_NO if this daemon could not handle the connection (i.e. malloc failed, etc). The socket will be closed in any case.

Definition at line 855 of file daemon.c.

References MHD_Connection::addr, MHD_Connection::addr_len, MHD_Daemon::apc, MHD_Daemon::apc_cls, MHD_Daemon::cleanup_connection_mutex, CLOSE, MHD_Daemon::connection_timeout, MHD_Connection::connection_timeout, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, create_thread(), MHD_Connection::daemon, DLL_insert, DLL_remove, MHD_Connection::last_activity, MHD_Daemon::max_connections, MHD_handle_connection(), MHD_ip_limit_add(), MHD_ip_limit_del(), MHD_monotonic_time(), MHD_NO, MHD_PANIC, MHD_set_http_callbacks_(), MHD_set_https_callbacks(), MHD_TLS_CONNECTION_INIT, MHD_USE_POLL, MHD_USE_SSL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::pool, MHD_Connection::recv_cls, recv_param_adapter(), MHD_Connection::send_cls, send_param_adapter(), SHUTDOWN, MHD_Connection::socket_fd, MHD_Connection::state, and STRERROR.

Referenced by MHD_accept_connection().

Here is the call graph for this function:

Here is the caller graph for this function:

static void MHD_cleanup_connections ( struct MHD_Daemon daemon  )  [static]

Free resources associated with all closed connections. (destroy responses, free buffers, etc.). All closed connections are kept in the "cleanup" doubly-linked list.

Parameters:
daemon daemon to clean up

Definition at line 1192 of file daemon.c.

References MHD_Connection::addr, MHD_Connection::addr_len, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::cleanup_head, MHD_Daemon::cleanup_tail, CLOSE, MHD_Connection::daemon, DLL_remove, MHD_Daemon::max_connections, MHD_destroy_response(), MHD_ip_limit_del(), MHD_NO, MHD_PANIC, MHD_pool_destroy(), MHD_USE_THREAD_PER_CONNECTION, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::pool, MHD_Connection::response, MHD_Connection::socket_fd, and MHD_Connection::thread_joined.

Referenced by close_all_connections(), MHD_run(), and MHD_select_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

void ATTRIBUTE_DESTRUCTOR MHD_fini (  ) 

Definition at line 2805 of file daemon.c.

union MHD_DaemonInfo* MHD_get_daemon_info ( struct MHD_Daemon daemon,
enum MHD_DaemonInfoType  infoType,
  ... 
)

Obtain information about the given daemon (not fully implemented!).

Parameters:
daemon what daemon to get information about
infoType what information is desired?
... depends on infoType
Returns:
NULL if this information is not available (or if the infoType is unknown)

Definition at line 2724 of file daemon.c.

References MHD_DAEMON_INFO_LISTEN_FD, NULL, and MHD_Daemon::socket_fd.

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

Obtain the select sets for this daemon.

Parameters:
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
Returns:
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call.

Definition at line 522 of file daemon.c.

References MHD_Daemon::connections_head, MHD_Connection::daemon, MHD_connection_get_fdset(), MHD_NO, MHD_USE_POLL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, NULL, MHD_Daemon::options, MHD_Daemon::shutdown, and MHD_Daemon::socket_fd.

Referenced by MHD_select().

Here is the call graph for this function:

Here is the caller graph for this function:

static struct MHD_Daemon* MHD_get_master ( struct MHD_Daemon daemon  )  [static]

Trace up to and return master daemon. If the supplied daemon is a master, then return the daemon itself.

Parameters:
daemon handle to a daemon
Returns:
master daemon handle

Definition at line 127 of file daemon.c.

References MHD_Daemon::master, and NULL.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

int MHD_get_timeout ( struct MHD_Daemon daemon,
unsigned MHD_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 should at most block, not the timeout value set for connections.

Parameters:
daemon daemon to query for timeout
timeout set to the timeout (in milliseconds)
Returns:
MHD_YES on success, MHD_NO if timeouts are not used (or no connections exist that would necessiate the use of a timeout right now).

Definition at line 1253 of file daemon.c.

References MHD_Connection::connection_timeout, MHD_Daemon::connections_head, MHD_Connection::daemon, MHD_Connection::last_activity, MHD_monotonic_time(), MHD_NO, MHD_USE_SSL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, NULL, and MHD_Daemon::options.

Referenced by MHD_select().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* MHD_get_version ( void   ) 

Obtain the version of this library

Returns:
static version string, e.g. "0.4.1"

Definition at line 2766 of file daemon.c.

static void* MHD_handle_connection ( void *  data  )  [static]

Main function of the thread that handles an individual connection when MHD_USE_THREAD_PER_CONNECTION is set.

Parameters:
data the 'struct MHD_Connection' this thread will handle
Returns:
always NULL

Definition at line 569 of file daemon.c.

References MHD_Daemon::connection_timeout, MHD_Connection::daemon, MHD_Connection::idle_handler, MHD_Connection::last_activity, MHD_CONNECTION_CHUNKED_BODY_UNREADY, MHD_connection_close(), MHD_CONNECTION_CLOSED, MHD_connection_get_fdset(), MHD_connection_get_pollfd(), MHD_CONNECTION_IN_CLEANUP, MHD_CONNECTION_NORMAL_BODY_UNREADY, MHD_destroy_response(), MHD_monotonic_time(), MHD_NO, MHD_POLL_ACTION_IN, MHD_POLL_ACTION_OUT, MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_USE_POLL, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::read_handler, MHD_Connection::response, SELECT, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Connection::state, and STRERROR.

Referenced by MHD_add_connection().

Here is the call graph for this function:

Here is the caller graph for this function:

void ATTRIBUTE_CONSTRUCTOR MHD_init (  ) 

Initialize do setup work.

Definition at line 2789 of file daemon.c.

References mhd_panic, mhd_panic_cls, mhd_panic_std(), and NULL.

Here is the call graph for this function:

static int MHD_ip_addr_compare ( const void *  a1,
const void *  a2 
) [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.

Parameters:
a1 first address to compare
a2 second address to compare
Returns:
-1, 0 or 1 depending on result of compare

Definition at line 209 of file daemon.c.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

static int MHD_ip_addr_to_key ( const struct sockaddr *  addr,
socklen_t  addrlen,
struct MHD_IPCount *  key 
) [static]

Parse address and initialize 'key' using the address.

Parameters:
addr address to parse
addrlen number of bytes in addr
key where to store the parsed address
Returns:
MHD_YES on success and MHD_NO otherwise (e.g., invalid address type)

Definition at line 224 of file daemon.c.

References MHD_NO, and MHD_YES.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

static void MHD_ip_count_lock ( struct MHD_Daemon daemon  )  [static]

Lock shared structure for IP connection counts and connection DLLs.

Parameters:
daemon handle to daemon where lock is

Definition at line 175 of file daemon.c.

References MHD_PANIC, and MHD_Daemon::per_ip_connection_mutex.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

static void MHD_ip_count_unlock ( struct MHD_Daemon daemon  )  [static]

Unlock shared structure for IP connection counts and connection DLLs.

Parameters:
daemon handle to daemon where lock is

Definition at line 190 of file daemon.c.

References MHD_PANIC, and MHD_Daemon::per_ip_connection_mutex.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

static int MHD_ip_limit_add ( struct MHD_Daemon daemon,
const struct sockaddr *  addr,
socklen_t  addrlen 
) [static]

Check if IP address is over its limit.

Parameters:
daemon handle to daemon where connection counts are tracked
addr address to add (or increment counter)
addrlen number of bytes in addr
Returns:
Return MHD_YES if IP below limit, MHD_NO if IP has surpassed limit. Also returns MHD_NO if fails to allocate memory.

Definition at line 265 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 MHD_add_connection().

Here is the call graph for this function:

Here is the caller graph for this function:

static void MHD_ip_limit_del ( struct MHD_Daemon daemon,
const struct sockaddr *  addr,
socklen_t  addrlen 
) [static]

Decrement connection count for IP address, removing from table count reaches 0

Parameters:
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 329 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 MHD_add_connection(), and MHD_cleanup_connections().

Here is the call graph for this function:

Here is the caller graph for this function:

static void mhd_panic_std ( void *  cls,
const char *  file,
unsigned int  line,
const char *  reason 
) [static]

Default implementation of the panic function, prints an error message and aborts.

Parameters:
cls unused
file name of the file with the problem
line line number with the problem
msg error message with details

Definition at line 95 of file daemon.c.

Referenced by MHD_init().

Here is the caller graph for this function:

static int MHD_poll ( struct MHD_Daemon daemon,
int  may_block 
) [static]

Do 'poll'-based processing.

Parameters:
daemon daemon to run poll loop for
may_block YES if blocking, NO if non-blocking
Returns:
MHD_NO on serious errors, MHD_YES on success

Definition at line 1587 of file daemon.c.

References MHD_NO, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Daemon::options, and MHD_Daemon::shutdown.

Referenced by MHD_run(), and MHD_select_thread().

Here is the caller graph for this function:

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.

Returns:
MHD_YES on success, MHD_NO if this daemon was not started with the right options for this call.

Definition at line 1614 of file daemon.c.

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

Here is the call graph for this function:

static int MHD_select ( struct MHD_Daemon daemon,
int  may_block 
) [static]

Main select call.

Parameters:
daemon daemon to run select loop for
may_block YES if blocking, NO if non-blocking
Returns:
MHD_NO on serious errors, MHD_YES on success

Definition at line 1302 of file daemon.c.

References MHD_accept_connection(), MHD_get_fdset(), MHD_get_timeout(), MHD_LONG_LONG, MHD_NO, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, NULL, MHD_Daemon::options, MHD_Connection::read_handler, SELECT, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Daemon::socket_fd, STRERROR, and MHD_Daemon::wpipe.

Referenced by MHD_run(), and MHD_select_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

static void* MHD_select_thread ( void *  cls  )  [static]

Thread that runs the select loop until the daemon is explicitly shut down.

Parameters:
cls 'struct MHD_Deamon' to run select loop in a thread for
Returns:
always NULL (on shutdown)

Definition at line 1637 of file daemon.c.

References MHD_cleanup_connections(), MHD_poll(), MHD_select(), MHD_USE_POLL, MHD_YES, NULL, MHD_Daemon::options, and MHD_Daemon::shutdown.

Referenced by MHD_start_daemon_va().

Here is the call graph for this function:

Here is the caller graph for this function:

void MHD_set_panic_func ( MHD_PanicCallback  cb,
void *  cls 
)

Sets the global error handler to a different implementation. "cb" will only be called in the case of typically fatal, serious internal consistency issues. These issues should only arise in the case of serious memory corruption or similar problems with the architecture. While "cb" is allowed to return and MHD will then try to continue, this is never safe.

The default implementation that is used if no panic function is set simply prints an error message and calls "abort". Alternative implementations might call "exit" or other similar functions.

Parameters:
cb new error handler
cls passed to error handler

Definition at line 2753 of file daemon.c.

References mhd_panic, and mhd_panic_cls.

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

Start a webserver on the given port.

Parameters:
port port to bind to
apc callback to call to check which clients will be allowed to connect
apc_cls extra argument to apc
dh default handler for all URIs
dh_cls extra argument to dh
Returns:
NULL on error, handle to daemon on success

Definition at line 1665 of file daemon.c.

References MHD_start_daemon_va().

Here is the call graph for this function:

struct MHD_Daemon* MHD_start_daemon_va ( unsigned int  options,
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:
port port to bind to
apc callback to call to check which clients will be allowed to connect
apc_cls extra argument to apc
dh default handler for all URIs
dh_cls extra argument to dh
Returns:
NULL on error, handle to daemon on success

Definition at line 2058 of file daemon.c.

References MHD_Daemon::apc, MHD_Daemon::apc_cls, BIND, CLOSE, MHD_Daemon::connection_timeout, create_socket(), create_thread(), MHD_Daemon::default_handler, MHD_Daemon::default_handler_cls, LISTEN, MHD_Daemon::max_connections, MHD_http_unescape(), MHD_MAX_CONNECTIONS_DEFAULT, MHD_POOL_SIZE_DEFAULT, MHD_select_thread(), MHD_USE_DEBUG, MHD_USE_IPv6, MHD_USE_NO_LISTEN_SOCKET, MHD_USE_POLL, MHD_USE_SELECT_INTERNALLY, MHD_USE_SSL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, NULL, MHD_Daemon::options, parse_options_va(), PIPE, MHD_Daemon::pool_size, MHD_Daemon::port, SETSOCKOPT, MHD_Daemon::socket_fd, STRERROR, MHD_Daemon::unescape_callback, and MHD_Daemon::wpipe.

Referenced by MHD_start_daemon().

Here is the call graph for this function:

Here is the caller graph for this function:

void MHD_stop_daemon ( struct MHD_Daemon daemon  ) 

Shutdown an http daemon

Parameters:
daemon daemon to stop

Definition at line 2614 of file daemon.c.

References MHD_Connection::daemon, MHD_PANIC, MHD_YES, NULL, MHD_Daemon::shutdown, MHD_Daemon::socket_fd, MHD_Daemon::worker_pool, MHD_Daemon::worker_pool_size, MHD_Daemon::wpipe, and WRITE.

static int parse_options ( struct MHD_Daemon daemon,
const struct sockaddr **  servaddr,
  ... 
) [static]

Parse a list of options given as varargs.

Parameters:
daemon the daemon to initialize
servaddr where to store the server's listen address
... the options
Returns:
MHD_YES on success, MHD_NO on error

Definition at line 1716 of file daemon.c.

References parse_options_va().

Referenced by parse_options_va().

Here is the call graph for this function:

Here is the caller graph for this function:

static int parse_options_va ( struct MHD_Daemon daemon,
const struct sockaddr **  servaddr,
va_list  ap 
) [static]

Parse a list of options given as varargs.

Parameters:
daemon the daemon to initialize
servaddr where to store the server's listen address
ap the options
Returns:
MHD_YES on success, MHD_NO on error

Definition at line 1739 of file daemon.c.

References MHD_Daemon::connection_timeout, MHD_Daemon::max_connections, MHD_NO, MHD_OPTION_ARRAY, MHD_OPTION_CONNECTION_LIMIT, MHD_OPTION_CONNECTION_MEMORY_LIMIT, MHD_OPTION_CONNECTION_TIMEOUT, MHD_OPTION_DIGEST_AUTH_RANDOM, MHD_OPTION_END, MHD_OPTION_EXTERNAL_LOGGER, MHD_OPTION_HTTPS_CRED_TYPE, MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_KEY, MHD_OPTION_HTTPS_MEM_TRUST, MHD_OPTION_HTTPS_PRIORITIES, MHD_OPTION_LISTEN_SOCKET, MHD_OPTION_NONCE_NC_SIZE, MHD_OPTION_NOTIFY_COMPLETED, MHD_OPTION_PER_IP_CONNECTION_LIMIT, MHD_OPTION_SOCK_ADDR, MHD_OPTION_THREAD_POOL_SIZE, MHD_OPTION_THREAD_STACK_SIZE, MHD_OPTION_UNESCAPE_CALLBACK, MHD_OPTION_URI_LOG_CALLBACK, MHD_USE_SSL, MHD_YES, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, NULL, MHD_OptionItem::option, MHD_Daemon::options, parse_options(), MHD_Daemon::per_ip_connection_limit, MHD_Daemon::pool_size, MHD_OptionItem::ptr_value, MHD_Daemon::socket_fd, MHD_Daemon::thread_stack_size, 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().

Here is the call graph for this function:

Here is the caller graph for this function:

static ssize_t recv_param_adapter ( struct MHD_Connection connection,
void *  other,
size_t  i 
) [static]

Callback for receiving data from the socket.

Parameters:
conn the MHD connection structure
other where to write received data to
i maximum size of other (in bytes)
Returns:
number of bytes actually received

Definition at line 709 of file daemon.c.

References MHD_Connection::daemon, MHD_CONNECTION_CLOSED, MHD_USE_SSL, MSG_NOSIGNAL, MHD_Daemon::options, RECV, MHD_Connection::socket_fd, and MHD_Connection::state.

Referenced by MHD_add_connection().

Here is the caller graph for this function:

static ssize_t send_param_adapter ( struct MHD_Connection connection,
const void *  other,
size_t  i 
) [static]

Callback for writing data to the socket.

Parameters:
conn the MHD connection structure
other data to write
i number of bytes to write
Returns:
actual number of bytes written

Definition at line 734 of file daemon.c.

References MHD_Connection::daemon, MHD_Response::fd, MHD_Response::fd_off, MHD_CONNECTION_CLOSED, MHD_USE_SSL, MSG_NOSIGNAL, NULL, MHD_Daemon::options, MHD_Connection::response, MHD_Connection::response_write_position, SEND, MHD_Connection::socket_fd, MHD_Connection::state, MHD_Response::total_size, MHD_Connection::write_buffer_append_offset, and MHD_Connection::write_buffer_send_offset.

Referenced by MHD_add_connection().

Here is the caller graph for this function:


Variable Documentation

MHD_PanicCallback mhd_panic

Handler for fatal errors.

Definition at line 111 of file daemon.c.

Referenced by build_header_response(), MHD_create_post_processor(), MHD_init(), MHD_set_panic_func(), post_process_multipart(), post_process_urlencoded(), process_request_body(), and try_ready_normal_body().

void* mhd_panic_cls

Closure argument for "mhd_panic".

Definition at line 116 of file daemon.c.

Referenced by build_header_response(), MHD_create_post_processor(), MHD_init(), MHD_set_panic_func(), post_process_multipart(), post_process_urlencoded(), process_request_body(), and try_ready_normal_body().


Generated on Thu Sep 27 17:55:17 2012 for GNU libmicrohttpd by  doxygen 1.4.7