daemon.c File Reference

A minimal-HTTP server library. More...

#include "internal.h"
#include "response.h"
#include "connection.h"
#include "memorypool.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   (1024 * 1024)
#define DEBUG_CLOSE   MHD_NO
#define DEBUG_CONNECT   MHD_NO

Functions

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 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 long long *timeout)
static int MHD_select (struct MHD_Daemon *daemon, int may_block)
int MHD_run (struct MHD_Daemon *daemon)
static void * MHD_select_thread (void *cls)
struct MHD_DaemonMHD_start_daemon (unsigned int options, unsigned short port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
void MHD_stop_daemon (struct MHD_Daemon *daemon)
static void sigalrmHandler (int sig)
void __attribute__ ((constructor))
void __attribute__ ((destructor))

Variables

static struct sigaction sig
static struct sigaction old


Detailed Description

A minimal-HTTP server library.

Author:
Daniel Pittman

Christian Grothoff

Definition in file daemon.c.


Define Documentation

#define DEBUG_CLOSE   MHD_NO

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

Definition at line 47 of file daemon.c.

#define DEBUG_CONNECT   MHD_NO

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

Definition at line 53 of file daemon.c.

#define MHD_MAX_CONNECTIONS_DEFAULT   FD_SETSIZE -4

Default connection limit.

Definition at line 36 of file daemon.c.

Referenced by MHD_start_daemon().

#define MHD_POOL_SIZE_DEFAULT   (1024 * 1024)

Default memory allowed per connection.

Definition at line 41 of file daemon.c.

Referenced by MHD_start_daemon().


Function Documentation

void __attribute__ ( (destructor)   ) 

Definition at line 773 of file daemon.c.

References old, sig, and SIGALRM.

void __attribute__ ( (constructor)   ) 

Initialize the signal handler for SIGALRM.

Definition at line 763 of file daemon.c.

References old, sig, SIGALRM, and sigalrmHandler().

Here is the call 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.

Definition at line 173 of file daemon.c.

References ACCEPT, MHD_Connection::addr, MHD_Connection::addr_len, MHD_Daemon::apc, MHD_Daemon::apc_cls, CLOSE, MHD_Daemon::connections, MHD_Connection::daemon, MHD_Connection::last_activity, MHD_Daemon::max_connections, MHD_handle_connection(), MHD_NO, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, MHD_Daemon::options, MHD_Daemon::per_ip_connection_limit, MHD_Connection::pid, MHD_Connection::pool, SHUTDOWN, MHD_Connection::socket_fd, 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:

static void MHD_cleanup_connections ( struct MHD_Daemon daemon  )  [static]

Free resources associated with all closed connections. (destroy responses, free buffers, etc.). A connection is known to be closed if the socket_fd is -1.

Definition at line 328 of file daemon.c.

References MHD_Connection::addr, MHD_Daemon::connections, MHD_Daemon::max_connections, MHD_destroy_response(), MHD_pool_destroy(), MHD_USE_THREAD_PER_CONNECTION, MHD_Connection::next, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::pool, MHD_Connection::response, SIGALRM, and MHD_Connection::socket_fd.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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

Definition at line 64 of file daemon.c.

References MHD_Daemon::connections, MHD_connection_get_fdset(), MHD_NO, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, 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:

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

Parameters:
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 377 of file daemon.c.

References MHD_Daemon::connection_timeout, MHD_Daemon::connections, MHD_Connection::last_activity, MHD_NO, MHD_YES, and MHD_Connection::next.

Referenced by MHD_select().

Here is the caller graph for this function:

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

Main function of the thread that handles an individual connection.

Definition at line 104 of file daemon.c.

References CLOSE, MHD_Daemon::connection_timeout, MHD_Connection::daemon, MHD_Connection::last_activity, MHD_connection_get_fdset(), MHD_connection_handle_idle(), MHD_connection_handle_read(), MHD_connection_handle_write(), SELECT, SHUTDOWN, MHD_Daemon::shutdown, MHD_Connection::socket_fd, and STRERROR.

Referenced by MHD_accept_connection().

Here is the call graph for this function:

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 519 of file daemon.c.

References MHD_cleanup_connections(), MHD_NO, MHD_select(), 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:
may_block YES if blocking, NO if non-blocking
Returns:
MHD_NO on serious errors, MHD_YES on success

Definition at line 413 of file daemon.c.

References MHD_Daemon::connections, MHD_accept_connection(), MHD_connection_handle_idle(), MHD_connection_handle_read(), MHD_connection_handle_write(), MHD_get_fdset(), MHD_get_timeout(), MHD_NO, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, MHD_Daemon::options, SELECT, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Daemon::socket_fd, and STRERROR.

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.

Definition at line 536 of file daemon.c.

References MHD_cleanup_connections(), MHD_NO, MHD_select(), MHD_YES, and MHD_Daemon::shutdown.

Referenced by MHD_start_daemon().

Here is the call graph for this function:

Here is the caller graph for this function:

struct MHD_Daemon* MHD_start_daemon ( unsigned int  options,
unsigned short  port,
MHD_AcceptPolicyCallback  apc,
void *  apc_cls,
MHD_AccessHandlerCallback  dh,
void *  dh_cls,
  ... 
) [read]

void MHD_stop_daemon ( struct MHD_Daemon daemon  ) 

static void sigalrmHandler ( int  sig  )  [static]

Definition at line 756 of file daemon.c.

Referenced by __attribute__().

Here is the caller graph for this function:


Variable Documentation

struct sigaction old [static]

Definition at line 753 of file daemon.c.

Referenced by __attribute__().

struct sigaction sig [static]

Definition at line 751 of file daemon.c.

Referenced by __attribute__().


Generated on Fri Oct 3 15:57:46 2008 for GNU libmicrohttpd by  doxygen 1.5.6