fastcgi++
3.1alpha
A C++ FastCGI/Web API
|
General task and protocol management class base. More...
#include <fastcgi++/manager.hpp>
Public Member Functions | |
Manager_base (unsigned threads) | |
Sole constructor. More... | |
~Manager_base () | |
void | terminate () |
Call from any thread to terminate the Manager. More... | |
void | stop () |
Call from any thread to stop the Manager. More... | |
void | start () |
Call from any thread to start the Manager. More... | |
void | join () |
Block until a stop() or terminate() is called and completed. More... | |
bool | listen () |
Listen to the default Fastcgi socket. More... | |
bool | listen (const char *name, uint32_t permissions=0xffffffffUL, const char *owner=nullptr, const char *group=nullptr) |
Listen to a named socket. More... | |
bool | listen (const char *interface, const char *service) |
Listen to a TCP port. More... | |
void | push (Protocol::RequestId id, Message &&message) |
Pass a message to a request. More... | |
void | reuseAddress (bool value) |
Should we set socket option to reuse address. More... | |
void | resizeThreads (unsigned threads) |
Call before start to change the number of threads. More... | |
Static Public Member Functions | |
static void | setupSignals () |
Configure the handlers for POSIX signals. More... | |
Protected Member Functions | |
virtual std::unique_ptr< Request_base > | makeRequest (const Protocol::RequestId &id, const Protocol::Role &role, bool kill)=0 |
Make a request object. More... | |
Protected Attributes | |
Transceiver | m_transceiver |
Handles low level communication with the other side. More... | |
Private Member Functions | |
void | handler () |
General handling function to have it's own thread. More... | |
void | localHandler () |
Handles management messages. More... | |
Static Private Member Functions | |
static void | signalHandler (int signum) |
General function to handler POSIX signals. More... | |
Private Attributes | |
std::queue< Protocol::RequestId > | m_tasks |
Queue for pending tasks. More... | |
std::mutex | m_tasksMutex |
Thread safe our tasks. More... | |
Protocol::Requests< std::unique_ptr< Request_base > > | m_requests |
An associative container for our requests. More... | |
std::shared_timed_mutex | m_requestsMutex |
Thread safe our requests. More... | |
std::queue< std::pair< Message, Socket > > | m_messages |
Local messages. More... | |
std::mutex | m_messagesMutex |
Thread safe our local messages. More... | |
bool | m_terminate |
True when the manager should be terminating. More... | |
bool | m_stop |
True when the manager should be stopping. More... | |
std::mutex | m_startStopMutex |
Thread safe starting and stopping. More... | |
std::vector< std::thread > | m_threads |
Threads our manager is running in. More... | |
std::condition_variable | m_wake |
Condition variable to wake handler() threads up. More... | |
Static Private Attributes | |
static Manager_base * | instance =nullptr |
Pointer to the Manager object. More... | |
General task and protocol management class base.
Handles all task and protocol management, creation/destruction of requests and passing of messages to requests.
To operate this class you need to do the following:
Definition at line 81 of file manager.hpp.
Fastcgipp::Manager_base::Manager_base | ( | unsigned | threads | ) |
Sole constructor.
[in] | threads | Number of threads to use for request handling |
Definition at line 34 of file manager.cpp.
Fastcgipp::Manager_base::~Manager_base | ( | ) |
Definition at line 428 of file manager.cpp.
References DIAG_LOG.
|
private |
General handling function to have it's own thread.
Definition at line 254 of file manager.cpp.
Referenced by start().
void Fastcgipp::Manager_base::join | ( | ) |
Block until a stop() or terminate() is called and completed.
Definition at line 91 of file manager.cpp.
|
inline |
Listen to the default Fastcgi socket.
Calling this simply adds the default socket used on FastCGI applications that are initialized from HTTP servers.
Definition at line 159 of file manager.hpp.
|
inline |
Listen to a TCP port.
Listen on a specific interface and TCP port.
[in] | interface | Interface to listen on. This could be an IP address or a hostname. If you don't want to specify the interface, pass nullptr. |
[in] | service | Port or service to listen on. This could be a service name, or a string representation of a port number. |
Definition at line 200 of file manager.hpp.
|
inline |
Listen to a named socket.
Listen on a named socket. In the Unix world this would be a path. In the Windows world I have no idea what this would be.
[in] | name | Name of socket (path in Unix world). |
[in] | permissions | Permissions of socket. If you do not wish to set the permissions, leave it as it's default value of 0xffffffffUL. |
[in] | owner | Owner (username) of socket. Leave as nullptr if you do not wish to set it. |
[in] | group | Group (group name) of socket. Leave as nullptr if you do not wish to set it. |
Definition at line 179 of file manager.hpp.
|
inlineprivate |
Handles management messages.
This function is called by handler() in the case that a management message is recieved.
Definition at line 143 of file manager.cpp.
References Fastcgipp::Block::begin(), Fastcgipp::Protocol::Header::contentLength, Fastcgipp::Message::data, Fastcgipp::Block::end(), ERROR_LOG, Fastcgipp::Protocol::Header::fcgiId, Fastcgipp::Protocol::GET_VALUES, Fastcgipp::Logging::header(), Fastcgipp::Protocol::maxConnsReply, Fastcgipp::Protocol::maxReqsReply, Fastcgipp::Protocol::mpxsConnsReply, Fastcgipp::Protocol::Header::paddingLength, Fastcgipp::Protocol::processParamHeader(), Fastcgipp::Message::type, Fastcgipp::Protocol::Header::type, Fastcgipp::Protocol::UnknownType::type, Fastcgipp::Protocol::UNKNOWN_TYPE, Fastcgipp::Protocol::version, and Fastcgipp::Protocol::Header::version.
|
protectedpure virtual |
Make a request object.
Implemented in Fastcgipp::Manager< RequestT >.
void Fastcgipp::Manager_base::push | ( | Protocol::RequestId | id, |
Message && | message | ||
) |
Pass a message to a request.
Definition at line 332 of file manager.cpp.
References Fastcgipp::Protocol::badFcgiId, Fastcgipp::Protocol::BEGIN_REQUEST, Fastcgipp::Logging::header(), Fastcgipp::Protocol::BeginRequest::kill(), Fastcgipp::Protocol::BeginRequest::role, and WARNING_LOG.
void Fastcgipp::Manager_base::resizeThreads | ( | unsigned | threads | ) |
Call before start to change the number of threads.
If the Manager is already running this will do nothing.
[in] | threads | Number of threads to use for request handling |
Definition at line 417 of file manager.cpp.
|
inline |
Should we set socket option to reuse address.
[in] | status | Set to true if you want to reuse address. False otherwise (default). |
Definition at line 215 of file manager.hpp.
|
static |
Configure the handlers for POSIX signals.
By calling this function appropriate handlers will be set up for SIGPIPE, SIGUSR1 and SIGTERM.
Definition at line 100 of file manager.cpp.
References signalHandler().
|
staticprivate |
General function to handler POSIX signals.
Definition at line 112 of file manager.cpp.
References DIAG_LOG, and WARNING_LOG.
Referenced by setupSignals().
void Fastcgipp::Manager_base::start | ( | ) |
void Fastcgipp::Manager_base::stop | ( | ) |
Call from any thread to stop the Manager.
This function is intended to be called from a signal handler in the case of of a SIGUSR1. It is similar to terminate() except the Manager will wait until all requests are complete before halting.
Definition at line 68 of file manager.cpp.
void Fastcgipp::Manager_base::terminate | ( | ) |
Call from any thread to terminate the Manager.
This function is intended to be called from a thread separate from the Manager in order to terminate it. It should also be called by a signal handler in the case of of a SIGTERM. It will force the manager to terminate immediately.
Definition at line 60 of file manager.cpp.
|
staticprivate |
Pointer to the Manager object.
Definition at line 289 of file manager.hpp.
Referenced by Manager_base().
Local messages.
Definition at line 255 of file manager.hpp.
|
private |
Thread safe our local messages.
Definition at line 258 of file manager.hpp.
|
private |
An associative container for our requests.
Definition at line 249 of file manager.hpp.
|
private |
Thread safe our requests.
Definition at line 252 of file manager.hpp.
|
private |
Thread safe starting and stopping.
Definition at line 277 of file manager.hpp.
|
private |
True when the manager should be stopping.
Definition at line 274 of file manager.hpp.
|
private |
Queue for pending tasks.
Definition at line 243 of file manager.hpp.
|
private |
Thread safe our tasks.
Definition at line 246 of file manager.hpp.
|
private |
True when the manager should be terminating.
Definition at line 271 of file manager.hpp.
|
private |
Threads our manager is running in.
Definition at line 280 of file manager.hpp.
|
protected |
Handles low level communication with the other side.
Definition at line 239 of file manager.hpp.
|
private |
Condition variable to wake handler() threads up.
Definition at line 283 of file manager.hpp.