src/microspdy/daemon.c File Reference

daemon functionality More...

#include "platform.h"
#include "structures.h"
#include "internal.h"
#include "session.h"
#include "io.h"
Include dependency graph for daemon.c:

Go to the source code of this file.

Functions

static void spdyf_panic_std (void *cls, const char *file, unsigned int line, const char *reason)
static void spdyf_cleanup_sessions (struct SPDY_Daemon *daemon)
static void spdyf_close_all_sessions (struct SPDY_Daemon *daemon)
static int spdyf_parse_options_va (struct SPDY_Daemon *daemon, va_list valist)
void SPDY_set_panic_func (SPDY_PanicCallback cb, void *cls)
struct SPDY_DaemonSPDYF_start_daemon_va (uint16_t port, const char *certfile, const char *keyfile, SPDY_NewSessionCallback nscb, SPDY_SessionClosedCallback sccb, SPDY_NewRequestCallback nrcb, SPDY_NewDataCallback npdcb, SPDYF_NewStreamCallback fnscb, SPDYF_NewDataCallback fndcb, void *cls, void *fcls, va_list valist)
void SPDYF_stop_daemon (struct SPDY_Daemon *daemon)
int SPDYF_get_timeout (struct SPDY_Daemon *daemon, unsigned long long *timeout)
int SPDYF_get_fdset (struct SPDY_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, bool all)
void SPDYF_run (struct SPDY_Daemon *daemon)

Variables

SPDY_PanicCallback spdyf_panic = &spdyf_panic_std
void * spdyf_panic_cls

Detailed Description

daemon functionality

Author:
Andrey Uzunov

Definition in file daemon.c.


Function Documentation

void SPDY_set_panic_func ( SPDY_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 as well as failed assertions. While "cb" is allowed to return and the lib 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 161 of file daemon.c.

References spdyf_panic, and spdyf_panic_cls.

static void spdyf_cleanup_sessions ( struct SPDY_Daemon daemon  )  [static]

Free resources associated with all closed connections. (destroy responses, free buffers, etc.).

Parameters:
daemon daemon to clean up

Definition at line 74 of file daemon.c.

References SPDY_Daemon::cleanup_head, SPDY_Daemon::cleanup_tail, DLL_remove, NULL, and SPDYF_session_destroy().

Referenced by spdyf_close_all_sessions(), and SPDYF_run().

Here is the call graph for this function:

Here is the caller graph for this function:

static void spdyf_close_all_sessions ( struct SPDY_Daemon daemon  )  [static]

Closing of all connections handled by the daemon.

Parameters:
daemon SPDY daemon

Definition at line 95 of file daemon.c.

References NULL, SPDY_Daemon::sessions_head, SPDY_GOAWAY_STATUS_OK, spdyf_cleanup_sessions(), SPDYF_prepare_goaway(), SPDYF_session_close(), and SPDYF_session_write().

Referenced by SPDYF_stop_daemon().

Here is the call graph for this function:

Here is the caller graph for this function:

int SPDYF_get_fdset ( struct SPDY_Daemon daemon,
fd_set *  read_fd_set,
fd_set *  write_fd_set,
fd_set *  except_fd_set,
bool  all 
)

Obtain the select sets for this daemon. The idea of SPDYF_get_fdset is to return such descriptors that the select in the application can return and SPDY_run can be called only when this is really needed. That means not all sockets will be added to write_fd_set.

Parameters:
daemon daemon to get sets from
read_fd_set read set
write_fd_set write set
except_fd_set except set
all add all session's descriptors to write_fd_set or not
Returns:
largest FD added

Definition at line 432 of file daemon.c.

References SPDY_Session::fio_is_pending, SPDY_Session::last_activity, SPDY_Session::next, NULL, SPDY_Session::read_buffer_beginning, SPDY_Session::read_buffer_offset, SPDY_Session::response_queue_head, SPDY_Daemon::session_timeout, SPDY_Daemon::sessions_head, SPDY_Session::socket_fd, SPDY_Daemon::socket_fd, SPDY_SESSION_STATUS_CLOSING, SPDY_YES, SPDYF_monotonic_time(), SPDY_Session::status, and SPDY_Session::write_buffer.

Referenced by SPDY_get_fdset(), and SPDYF_run().

Here is the call graph for this function:

Here is the caller graph for this function:

int SPDYF_get_timeout ( struct SPDY_Daemon daemon,
unsigned long long *  timeout 
)

Obtain timeout value for select for this daemon. 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:
SPDY_YES on success, SPDY_NO if no connections exist that would necessiate the use of a timeout right now

Definition at line 392 of file daemon.c.

References SPDY_Session::fio_is_pending, SPDY_Session::last_activity, SPDY_Session::next, NULL, SPDY_Daemon::session_timeout, SPDY_Daemon::sessions_head, SPDY_NO, SPDY_YES, and SPDYF_monotonic_time().

Referenced by SPDY_get_timeout().

Here is the call graph for this function:

Here is the caller graph for this function:

static void spdyf_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
reason error message with details

Definition at line 42 of file daemon.c.

static int spdyf_parse_options_va ( struct SPDY_Daemon daemon,
va_list  valist 
) [static]

Parse a list of options given as varargs.

Parameters:
daemon the daemon to initialize
valist the options
Returns:
SPDY_YES on success, SPDY_NO on error

Definition at line 120 of file daemon.c.

References SPDY_Daemon::address, SPDY_Daemon::flags, SPDY_Daemon::io_subsystem, SPDY_Daemon::max_num_frames, SPDY_Daemon::options, SPDY_Daemon::session_timeout, SPDY_DAEMON_OPTION_END, SPDY_DAEMON_OPTION_FLAGS, SPDY_DAEMON_OPTION_IO_SUBSYSTEM, SPDY_DAEMON_OPTION_MAX_NUM_FRAMES, SPDY_DAEMON_OPTION_SESSION_TIMEOUT, SPDY_DAEMON_OPTION_SOCK_ADDR, SPDY_NO, SPDY_YES, and SPDYF_DEBUG.

Referenced by SPDYF_start_daemon_va().

Here is the caller graph for this function:

void SPDYF_run ( struct SPDY_Daemon daemon  ) 

Run webserver operations (without blocking unless in client callbacks). This method must be called in the client event loop.

Parameters:
daemon daemon to run

Definition at line 474 of file daemon.c.

References SPDY_Session::fio_is_pending, SPDY_Session::next, NULL, SPDY_Daemon::sessions_head, SPDY_Session::socket_fd, SPDY_Daemon::socket_fd, SPDY_NO, spdyf_cleanup_sessions(), SPDYF_get_fdset(), SPDYF_session_accept(), SPDYF_session_idle(), SPDYF_session_read(), and SPDYF_session_write().

Referenced by SPDY_run().

Here is the call graph for this function:

Here is the caller graph for this function:

struct SPDY_Daemon* SPDYF_start_daemon_va ( uint16_t  port,
const char *  certfile,
const char *  keyfile,
SPDY_NewSessionCallback  nscb,
SPDY_SessionClosedCallback  sccb,
SPDY_NewRequestCallback  nrcb,
SPDY_NewDataCallback  npdcb,
SPDYF_NewStreamCallback  fnscb,
SPDYF_NewDataCallback  fndcb,
void *  cls,
void *  fcls,
va_list  valist 
) [read]

Start a SPDDY webserver on the given port.

Parameters:
port port to bind to
certfile path to the certificate that will be used by server
keyfile path to the keyfile for the certificate
nscb callback called when a new SPDY session is established by a client
sccb callback called when a client closes the session
nrcb callback called when a client sends request
npdcb callback called when HTTP POST params are received after request
fnscb callback called when new stream is opened by a client
fndcb callback called when new data -- within a data frame -- is received by the server
cls extra argument to all of the callbacks without those specific only for the framing layer
fcls extra argument to all of the callbacks, specific only for the framing layer (those vars starting with 'f').
valist va_list of options (type-value pairs, terminated with SPDY_DAEMON_OPTION_END).
Returns:
NULL on error, handle to daemon on success

Definition at line 170 of file daemon.c.

References SPDY_Daemon::address, SPDY_Daemon::certfile, SPDY_Daemon::cls, SPDY_Daemon::fcls, SPDY_Daemon::fio_init, SPDY_Daemon::flags, SPDY_Daemon::fnew_stream_cb, SPDY_Daemon::freceived_data_cb, SPDY_Daemon::io_subsystem, SPDY_Daemon::keyfile, SPDY_Daemon::max_num_frames, SPDY_Daemon::new_request_cb, SPDY_Daemon::new_session_cb, NULL, SPDY_Daemon::port, SPDY_Daemon::received_data_cb, SPDY_Daemon::session_closed_cb, SPDY_Daemon::socket_fd, SPDY_DAEMON_FLAG_ONLY_IPV6, SPDY_IO_SUBSYSTEM_OPENSSL, SPDY_IO_SUBSYSTEM_RAW, SPDY_YES, SPDYF_DEBUG, SPDYF_io_set_daemon(), SPDYF_NUM_SENT_FRAMES_AT_ONCE, and spdyf_parse_options_va().

Referenced by SPDY_start_daemon().

Here is the call graph for this function:

Here is the caller graph for this function:

void SPDYF_stop_daemon ( struct SPDY_Daemon daemon  ) 

Shutdown the daemon.

Parameters:
daemon daemon to stop

Definition at line 373 of file daemon.c.

References SPDY_Daemon::address, SPDY_Daemon::certfile, SPDY_Daemon::fio_deinit, SPDY_Daemon::keyfile, SPDY_Daemon::options, SPDY_Daemon::socket_fd, SPDY_DAEMON_OPTION_SOCK_ADDR, and spdyf_close_all_sessions().

Referenced by SPDY_stop_daemon().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

SPDY_PanicCallback spdyf_panic = &spdyf_panic_std

Global handler for fatal errors.

Definition at line 58 of file daemon.c.

Referenced by SPDY_set_panic_func().

Global closure argument for "spdyf_panic".

Definition at line 64 of file daemon.c.

Referenced by SPDY_set_panic_func().


Generated on 11 Mar 2016 for GNU libmicrohttpd by  doxygen 1.6.1