/Users/maurits/Documents/studie/afstuderen/biosphere/daemon/thread.c File Reference

#include "thread.h"
#include "http.h"
#include "module.h"
#include "mutex.h"
#include "options.h"
#include "settings.h"
#include <biosphere.h>
#include <copy.h>
#include <list.h>
#include <apr_file_io.h>
#include <apr_strings.h>
#include <apr_network_io.h>
#include <apr_thread_proc.h>
#include <apr_time.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>

Include dependency graph for thread.c:

Go to the source code of this file.

Data Structures

struct  worker_info
struct  worker_thread_args
struct  shutdown_info

Defines

#define MAX_HEADER_CHECK_ATTEMPTS   4

Functions

static bs_status init_listen_socket (apr_socket_t **sock, apr_pool_t *mp)
static void remove_from_socket_list (apr_socket_t *sock)
static void add_to_socket_list (apr_socket_t *sock, apr_pool_t *mp)
static void *APR_THREAD_FUNC worker_thread_main (apr_thread_t *thd, void *data)
static bs_status setup_thread (apr_socket_t *sock)
bs_status init_threadsystem (apr_pool_t *mp)
static void remove_oldest_thread (void)
void lets_go_threaded (void)
static void *APR_THREAD_FUNC shutdown_thread_main (apr_thread_t *thd, void *sinfo)
bs_status stop_daemon (bs_uint32 num_usecs)

Variables

apr_pool_t * global_mp
static apr_socket_t * listener_socket
static bs_listsockets


Define Documentation

#define MAX_HEADER_CHECK_ATTEMPTS   4

The maximum number of socket_recv()s that will be performed before concluding that the HTTP headers are incomplete.

Definition at line 78 of file thread.c.

Referenced by worker_thread_main().


Function Documentation

static void add_to_socket_list ( apr_socket_t *  sock,
apr_pool_t *  mp 
) [static]

Add a given socket to the socket list and also create the timestamp

Definition at line 185 of file thread.c.

References list_append(), lock_thread_mux(), worker_info::pool, worker_info::sock, sockets, worker_info::ts, and unlock_thread_mux().

Referenced by worker_thread_main().

Here is the call graph for this function:

static bs_status init_listen_socket ( apr_socket_t **  sock,
apr_pool_t *  mp 
) [static]

Create a listening socket, and start listening on it.

Parameters:
sock Result pointer to the listening socket
mp Memory pool to use
Returns:
Status code.

Definition at line 97 of file thread.c.

References BS_ERROR, BS_OK, global_listen_port, and runtestsuite::rv.

Referenced by init_threadsystem().

static void remove_from_socket_list ( apr_socket_t *  sock  )  [static]

Remove the given socket from the socket list. Comparing pointers might seem a bit dangerous but this sockets will only be added (and removed) to the sockets list by the worker_thread_main() function.

Parameters:
sock The socket to remove from the list

Definition at line 167 of file thread.c.

References list_index(), list_remove(), list_size(), lock_thread_mux(), sockets, and unlock_thread_mux().

Referenced by remove_oldest_thread(), and worker_thread_main().

Here is the call graph for this function:

static void remove_oldest_thread ( void   )  [static]

Remove the oldest thread in the thread list.

Definition at line 323 of file thread.c.

References list_index(), list_size(), remove_from_socket_list(), and sockets.

Referenced by lets_go_threaded().

Here is the call graph for this function:

static bs_status setup_thread ( apr_socket_t *  sock  )  [static]

Setup a new worker thread.

Parameters:
sock The socket to use for the worker thread
mp Memory pool to use
Returns:
The created thread.

Definition at line 282 of file thread.c.

References BS_ERROR, BS_OK, worker_thread_args::pool, runtestsuite::rv, worker_thread_args::sock, and worker_thread_main().

Referenced by lets_go_threaded().

Here is the call graph for this function:

static void* APR_THREAD_FUNC shutdown_thread_main ( apr_thread_t *  thd,
void *  sinfo 
) [static]

This thread performs the shutdown process by first closing the listening socket to prevent any more connections. It then waits a number of seconds to allow remaining worker threads to finish their work and then proceeds to kill of any remaining threads, unloading all modules and exiting the daemon.

Parameters:
thd Pointer to the APR thread structure
pool The memory pool used by the thread

Definition at line 414 of file thread.c.

References BS_ERROR, BS_OK, list_index(), list_size(), listener_socket, lock_thread_mux(), shutdown_info::pool, sockets, unload_all_modules(), unlock_thread_mux(), and shutdown_info::wait_time.

Referenced by stop_daemon().

Here is the call graph for this function:

static void* APR_THREAD_FUNC worker_thread_main ( apr_thread_t *  thd,
void *  data 
) [static]

The main routine for the worker threads to follow. They are passed a socket to use for communicate with the client and try to receive, parse, handle and respond to his/her request. After this handling, the worker thread exits by returning (apr_thread_exit is not called).

Parameters:
thd Pointer to the thread structure
data Pointer to data passed to the thread. This will be the socket.

Definition at line 207 of file thread.c.

References add_to_socket_list(), handle_http_get(), handle_http_post(), HTTP_BUFFER_SIZE, MAX_HEADER_CHECK_ATTEMPTS, worker_thread_args::pool, received_full_headers(), remove_from_socket_list(), runtestsuite::rv, send_http_error(), and worker_thread_args::sock.

Referenced by setup_thread().

Here is the call graph for this function:


Variable Documentation

apr_socket_t* listener_socket [static]

Listener socket used by the daemon:

Definition at line 83 of file thread.c.

Referenced by init_threadsystem(), lets_go_threaded(), and shutdown_thread_main().

bs_list* sockets [static]

A mutex protected list of all active sockets.

Definition at line 88 of file thread.c.

Referenced by add_to_socket_list(), init_threadsystem(), lets_go_threaded(), remove_from_socket_list(), remove_oldest_thread(), and shutdown_thread_main().


Generated on Tue Jul 17 09:51:15 2007 for Bio-SPHERE by  doxygen 1.5.1