|
fastcgi++
A C++ FastCGI/Web API
|
General task and protocol management class. More...
#include <fastcgi++/manager.hpp>
Public Member Functions | |
| Manager (unsigned threads=std::thread::hardware_concurrency()) | |
| Sole constructor. More... | |
| 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... | |
Static Public Member Functions | |
| static void | setupSignals () |
| Configure the handlers for POSIX signals. More... | |
Protected Attributes | |
| Transceiver | m_transceiver |
| Handles low level communication with the other side. More... | |
Private Member Functions | |
| std::unique_ptr< Request_base > | makeRequest (const Protocol::RequestId &id, const Protocol::Role &role, bool kill) |
| Make a request object. More... | |
General task and protocol management class.
Handles all task and protocol management, creation/destruction of requests and passing of messages to requests. The template argument should be a class type derived from the Request class with at least the response() function defined.
To operate this class you need to do the following:
| RequestT | A class type derived from the Request class with at least the Request::response() function defined. |
Definition at line 282 of file manager.hpp.
|
inline |
Sole constructor.
| [in] | threads | Number of threads to use for request handling |
Definition at line 289 of file manager.hpp.
|
inherited |
Block until a stop() or terminate() is called and completed.
Definition at line 91 of file manager.cpp.
References Fastcgipp::Transceiver::join(), Fastcgipp::Manager_base::m_threads, and Fastcgipp::Manager_base::m_transceiver.
|
inlineinherited |
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 124 of file manager.hpp.
References Fastcgipp::Transceiver::listen(), and Fastcgipp::Manager_base::m_transceiver.
|
inlineinherited |
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 144 of file manager.hpp.
References Fastcgipp::Transceiver::listen(), and Fastcgipp::Manager_base::m_transceiver.
|
inlineinherited |
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 165 of file manager.hpp.
References Fastcgipp::Transceiver::listen(), Fastcgipp::Manager_base::m_transceiver, Fastcgipp::Manager_base::makeRequest(), and Fastcgipp::Manager_base::push().
|
inlineprivatevirtual |
Make a request object.
Implements Fastcgipp::Manager_base.
Definition at line 295 of file manager.hpp.
References Fastcgipp::Manager_base::m_transceiver, Fastcgipp::Manager_base::push(), and Fastcgipp::Transceiver::send().
|
inherited |
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::Manager_base::m_messages, Fastcgipp::Manager_base::m_messagesMutex, Fastcgipp::Manager_base::m_requests, Fastcgipp::Manager_base::m_requestsMutex, Fastcgipp::Manager_base::m_tasks, Fastcgipp::Manager_base::m_tasksMutex, Fastcgipp::Manager_base::m_wake, Fastcgipp::Manager_base::makeRequest(), Fastcgipp::Protocol::BeginRequest::role, Fastcgipp::Protocol::Header::type, and WARNING_LOG.
Referenced by Fastcgipp::Manager_base::listen(), and Fastcgipp::Manager< RequestT >::makeRequest().
|
staticinherited |
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 Fastcgipp::Manager_base::signalHandler().
|
inherited |
Call from any thread to start the Manager.
If the Manager is already running this will do nothing.
Definition at line 76 of file manager.cpp.
References DIAG_LOG, Fastcgipp::Manager_base::handler(), Fastcgipp::Manager_base::m_stop, Fastcgipp::Manager_base::m_tasksMutex, Fastcgipp::Manager_base::m_terminate, Fastcgipp::Manager_base::m_threads, Fastcgipp::Manager_base::m_transceiver, and Fastcgipp::Transceiver::start().
|
inherited |
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.
References Fastcgipp::Manager_base::m_stop, Fastcgipp::Manager_base::m_tasksMutex, Fastcgipp::Manager_base::m_transceiver, Fastcgipp::Manager_base::m_wake, and Fastcgipp::Transceiver::stop().
Referenced by Fastcgipp::Manager_base::signalHandler().
|
inherited |
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.
References Fastcgipp::Manager_base::m_tasksMutex, Fastcgipp::Manager_base::m_terminate, Fastcgipp::Manager_base::m_transceiver, Fastcgipp::Manager_base::m_wake, and Fastcgipp::Transceiver::terminate().
Referenced by Fastcgipp::Manager_base::signalHandler(), and Fastcgipp::Manager_base::~Manager_base().
|
protectedinherited |
Handles low level communication with the other side.
Definition at line 183 of file manager.hpp.
Referenced by Fastcgipp::Manager_base::join(), Fastcgipp::Manager_base::listen(), Fastcgipp::Manager_base::localHandler(), Fastcgipp::Manager< RequestT >::makeRequest(), Fastcgipp::Manager_base::start(), Fastcgipp::Manager_base::stop(), and Fastcgipp::Manager_base::terminate().
1.8.11