Public Member Functions | Protected Member Functions | Protected Attributes

base::MTSocketDaemon Class Reference

Multi-threaded socket daemon class. More...

#include <libppbase/base/MTSocketDaemon.h>

Inheritance diagram for base::MTSocketDaemon:
base::Daemon base::Mutex

List of all members.

Public Member Functions

virtual ~MTSocketDaemon ()
 Destructor.
int getClientTimeout () const
 Returns client timeout.
size_t getNumberOfActiveThreads ()
 Returns number of active (=busy) worker threads.
size_t getNumberOfConnections ()
 Returns number of pending connections.
size_t getNumberOfThreads ()
 Returns total number of worker threads.
int getMaxNumberOfThreads () const
 Returns max number of worker threads as specified in the env.
WorkPile< Socket * > * getWebQueue ()
 Returns the web queue.
WorkPile< Socket * > * getWorkerQueue ()
 Returns the worker queue.
ThreadListgetWorkerThreads ()
 Returns worker threads list.

Protected Member Functions

 MTSocketDaemon (const String &name)
 Constructor.
void closeSockets ()
 closes all sockets that this daemon has opened
virtual void config ()
 Configures the daemon.
virtual void createThreads (bool init)
 Creates threads.
virtual WorkerThreadcreateWorkerThread (time_t lifetime, bool web=false)=0
 Creates a new web or worker thread.
bool dumpState (bool force)
 Dumps the daemon state into the log file.
virtual void handler (Socket::socket_type fd, int what)
 Distributes a client connection to a free thread, or puts it into a queue.
virtual int loop ()
 The main loop.
virtual bool needRootPrivileges ()
 Checks if the daemon needs root privileges (e.g. to allocate ports under 1024).
void openSockets ()
 Allocates the configured ports and sockets.
virtual void terminateThreads ()
 Terminates all worker threads.

Protected Attributes

int _children
 number of forked processes
WorkPile< Socket * > _clientqueue
 queue of pending client connections
int _clienttimeout
 timeout in seconds when interacting with a client
int _fdtype [8]
 array of file descriptor types
size_t _nfds
 number of file descriptors to poll
int _port
 port number of main service
int _sslport
 port number of main service (SSL)
int _sslwebport
 port number of web interface (SSL)
ThreadList _threads
 list of other existing threads
bool _threads_waitexit
 flag: wait for worker threads to finish before exiting
int _udpport
 port number of udp port
int _webport
 port number for web interface
int _web_lifetime
 lifetime of an auxiliary web thread
int _web_max
 maximum number of web threads or processes
int _web_min
 minimum number of web threads
int _web_start
 start web thread after this many pending connections
WorkPile< Socket * > _webqueue
 queue of pending web connections
int _worker_lifetime
 lifetime of an auxiliary worker thread
int _worker_max
 maximum number of worker threads or processes
int _worker_min
 minimum number of worker threads
int _worker_start
 start worker thread after this many pending connections
ThreadList _workerthreads
 list of existing auxiliary/primary web/worker threads
struct pollfd _fd [8]
 file descriptors that daemon accepts connections from
String _unixsocket
 unix domain socket

Detailed Description

Multi-threaded socket daemon class.

Author:
Christoph Schwarz
Version:
$Id: MTSocketDaemon.h 21 2010-09-05 04:18:17Z cschwarz1 $

Constructor & Destructor Documentation

base::MTSocketDaemon::MTSocketDaemon ( const String name  )  [protected]

Constructor.

Parameters:
name daemon name

Member Function Documentation

virtual WorkerThread* base::MTSocketDaemon::createWorkerThread ( time_t  lifetime,
bool  web = false 
) [protected, pure virtual]

Creates a new web or worker thread.

Parameters:
lifetime time to live until (unix timestamp)
web true to create a web thread, false to create a worker thread
bool base::MTSocketDaemon::dumpState ( bool  force  )  [protected, virtual]

Dumps the daemon state into the log file.

The daemon state contains information on all worker threads

Parameters:
force force dump, otherwise it is only dumped if the last dump was more than one minute ago
Returns:
true if the state has been dumped, false if not

Reimplemented from base::Daemon.

int base::MTSocketDaemon::getClientTimeout (  )  const

Returns client timeout.

Returns:
the client timeout in seconds
int base::MTSocketDaemon::getMaxNumberOfThreads (  )  const

Returns max number of worker threads as specified in the env.

Returns:
the maximum number of worker threads
size_t base::MTSocketDaemon::getNumberOfActiveThreads (  ) 

Returns number of active (=busy) worker threads.

Returns:
the number of active threads
size_t base::MTSocketDaemon::getNumberOfConnections (  ) 

Returns number of pending connections.

Returns:
the number of pending connections
size_t base::MTSocketDaemon::getNumberOfThreads (  ) 

Returns total number of worker threads.

Returns:
the number of worker threads
WorkPile<Socket*>* base::MTSocketDaemon::getWebQueue (  ) 

Returns the web queue.

Returns:
the web queue
WorkPile<Socket*>* base::MTSocketDaemon::getWorkerQueue (  ) 

Returns the worker queue.

Returns:
the worker queue
ThreadList* base::MTSocketDaemon::getWorkerThreads (  ) 

Returns worker threads list.

Returns:
the list of worker threads
virtual void base::MTSocketDaemon::handler ( Socket::socket_type  fd,
int  what 
) [protected, virtual]

Distributes a client connection to a free thread, or puts it into a queue.

Parameters:
fd the file descriptor of the client connection
what the type of the client connection
virtual int base::MTSocketDaemon::loop (  )  [protected, virtual]

The main loop.

Returns:
the daemon's exit code

Implements base::Daemon.

virtual bool base::MTSocketDaemon::needRootPrivileges (  )  [protected, virtual]

Checks if the daemon needs root privileges (e.g. to allocate ports under 1024).

Returns:
true if it needs root privileges, false if not

Reimplemented from base::Daemon.


The documentation for this class was generated from the following file: