Multi-threaded socket daemon class. More...
#include <libppbase/base/MTSocketDaemon.h>
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. | |
ThreadList * | getWorkerThreads () |
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 WorkerThread * | createWorkerThread (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 |
Multi-threaded socket daemon class.
base::MTSocketDaemon::MTSocketDaemon | ( | const String & | name | ) | [protected] |
Constructor.
name | daemon name |
virtual WorkerThread* base::MTSocketDaemon::createWorkerThread | ( | time_t | lifetime, | |
bool | web = false | |||
) | [protected, pure virtual] |
Creates a new web or worker thread.
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
force | force dump, otherwise it is only dumped if the last dump was more than one minute ago |
Reimplemented from base::Daemon.
int base::MTSocketDaemon::getClientTimeout | ( | ) | const |
Returns client timeout.
int base::MTSocketDaemon::getMaxNumberOfThreads | ( | ) | const |
Returns max number of worker threads as specified in the env.
size_t base::MTSocketDaemon::getNumberOfActiveThreads | ( | ) |
Returns number of active (=busy) worker threads.
size_t base::MTSocketDaemon::getNumberOfConnections | ( | ) |
Returns number of pending connections.
size_t base::MTSocketDaemon::getNumberOfThreads | ( | ) |
Returns total number of worker threads.
Returns the web queue.
Returns the worker queue.
ThreadList* base::MTSocketDaemon::getWorkerThreads | ( | ) |
Returns worker threads list.
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.
fd | the file descriptor of the client connection | |
what | the type of the client connection |
virtual int base::MTSocketDaemon::loop | ( | ) | [protected, virtual] |
virtual bool base::MTSocketDaemon::needRootPrivileges | ( | ) | [protected, virtual] |
Checks if the daemon needs root privileges (e.g. to allocate ports under 1024).
Reimplemented from base::Daemon.