fastcgi++
|
General task and protocol management class. More...
#include <manager.hpp>
Classes | |
class | Requests |
Associative container type for active requests. More... |
Public Member Functions | |
Manager (int fd=0, bool doSetupSignals=true) | |
Construct from a file descriptor. | |
void | handler () |
General handling function to be called after construction. | |
void | push (Protocol::FullId id, Message message) |
Passes messages to requests. | |
size_t | getRequestsSize () const |
Return the amount of pending requests. | |
void | stop () |
Halter for the handler() function. | |
void | terminate () |
Terminator for the handler() function. | |
void | setupSignals () |
Configure the handlers for POSIX signals. | |
size_t | getMessagesSize () const |
Tells you the size of the message queue. |
Protected Member Functions | |
void | localHandler (Protocol::FullId id) |
Handles management messages. |
Protected Attributes | |
Transceiver | transceiver |
Handles low level communication with the other side. | |
Tasks | tasks |
Queue for pending tasks. | |
std::queue< Message > | messages |
A queue of messages for the manager itself. | |
bool | asleep |
Indicated whether or not the manager is currently in sleep mode. | |
boost::mutex | sleepMutex |
Mutex to make accessing asleep thread safe. | |
pthread_t | threadId |
The pthread id of the thread the handler() function is operating in. | |
bool | stopBool |
Boolean value indicating that handler() should halt. | |
boost::mutex | stopMutex |
Mutex to make stopBool thread safe. | |
bool | terminateBool |
Boolean value indication that handler() should terminate. | |
boost::mutex | terminateMutex |
Mutex to make terminateMutex thread safe. |
Private Attributes | |
Requests | requests |
Associative container type for active requests. |
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 all that needs to be done is creating an object and calling handler() on it.
T | Class that will handle individual requests. Should be derived from the Request class. |
Definition at line 185 of file manager.hpp.
|
inline |
Construct from a file descriptor.
The only piece of data required to construct a Manager object is a file descriptor to listen on for incoming connections. By default mod_fastcgi sets up file descriptor 0 to do this so it is the value passed by default to the constructor. The only time it would be another value is if an external FastCGI server was defined.
[in] | fd | File descriptor to listen on. |
[in] | doSetupSignals | If true, signal handlers will be set up for SIGTERM and SIGUSR1. If false, no signal handlers will be set up. |
Definition at line 199 of file manager.hpp.
|
inlineinherited |
Tells you the size of the message queue.
Definition at line 109 of file manager.hpp.
References Fastcgipp::ManagerPar::messages.
|
inline |
Return the amount of pending requests.
Definition at line 230 of file manager.hpp.
References Fastcgipp::Manager< T >::requests.
void Fastcgipp::Manager< T >::handler | ( | ) |
General handling function to be called after construction.
This function will loop continuously manager tasks and FastCGI requests until either the stop() function is called (obviously from another thread) or the appropriate signals are caught.
Definition at line 293 of file manager.hpp.
|
protectedinherited |
Handles management messages.
This function is called by handler() in the case that a management message is recieved. Although the request id of a management record is always 0, the Protocol::FullId associated with the message is passed to this function to keep track of it's associated file descriptor.
[in] | id | FullId associated with the messsage. |
Definition at line 65 of file manager.cpp.
References Fastcgipp::Message::data, Fastcgipp::Block::data, Fastcgipp::Protocol::GET_VALUES, Fastcgipp::Protocol::maxConnsReply, Fastcgipp::Protocol::maxReqsReply, Fastcgipp::Protocol::mpxsConnsReply, Fastcgipp::Protocol::processParamHeader(), Fastcgipp::Protocol::UNKNOWN_TYPE, and Fastcgipp::Protocol::version.
void Fastcgipp::Manager< T >::push | ( | Protocol::FullId | id, |
Message | message | ||
) |
Passes messages to requests.
Whenever a message needs to be passed to a request, it must be done through this function. Requests are associated with their Protocol::FullId value so that and the message itself is all that is needed. Calling this function from another thread is safe. Although this function can be called from outside the fastcgi++ library, the Request class contains a callback function based on this that is more usable. An id with a Protocol::RequestId of 0 means the message is destined for the Manager itself. Should a message by passed with an id that doesn't exist, it will be discarded.
[in] | id | The id of the request the message should go to |
[in] | message | The message itself |
Definition at line 247 of file manager.hpp.
References Fastcgipp::Protocol::BEGIN_REQUEST, Fastcgipp::Message::data, and Fastcgipp::Message::type.
|
inherited |
Configure the handlers for POSIX signals.
By calling this function appropriate handlers will be set up for SIGPIPE, SIGUSR1 and SIGTERM. It is called by default upon construction of a Manager object. Should the user want to override these handlers, it should be done post-construction.
Definition at line 53 of file manager.cpp.
References Fastcgipp::ManagerPar::signalHandler().
Referenced by Fastcgipp::ManagerPar::ManagerPar().
|
inherited |
Halter for the handler() function.
This function is intended to be called from a thread separate from the handler() in order to halt it. It should also be called by a signal handler in the case of of a SIGTERM. Once handler() has been halted it may be re-called to pick up exactly where it left off without any data loss.
Definition at line 24 of file manager.cpp.
|
inherited |
Terminator for the handler() function.
This function is intended to be called from a signal handler in the case of of a SIGUSR1. It is similar to stop() except that handler() will wait until all requests are complete before halting.
Definition at line 12 of file manager.cpp.
|
protectedinherited |
Indicated whether or not the manager is currently in sleep mode.
Definition at line 142 of file manager.hpp.
|
protectedinherited |
A queue of messages for the manager itself.
Definition at line 128 of file manager.hpp.
Referenced by Fastcgipp::ManagerPar::getMessagesSize().
|
private |
Associative container type for active requests.
This container associated the Protocol::FullId of each active request with a pointer to the actual Request object.
Definition at line 243 of file manager.hpp.
Referenced by Fastcgipp::Manager< T >::getRequestsSize().
|
protectedinherited |
Mutex to make accessing asleep thread safe.
Definition at line 144 of file manager.hpp.
|
protectedinherited |
Boolean value indicating that handler() should halt.
Definition at line 156 of file manager.hpp.
|
protectedinherited |
Mutex to make stopBool thread safe.
Definition at line 158 of file manager.hpp.
|
protectedinherited |
Queue for pending tasks.
This contains a queue of Protocol::FullId that need their handlers called.
Definition at line 125 of file manager.hpp.
|
protectedinherited |
Boolean value indication that handler() should terminate.
Definition at line 163 of file manager.hpp.
|
protectedinherited |
Mutex to make terminateMutex thread safe.
Definition at line 165 of file manager.hpp.
|
protectedinherited |
The pthread id of the thread the handler() function is operating in.
Although this library is intended to be used with boost::thread and not pthread, the underlying pthread id of the handler() function is needed to call pthread_kill() when sleep is to be interrupted.
Definition at line 150 of file manager.hpp.
|
protectedinherited |
Handles low level communication with the other side.
Definition at line 113 of file manager.hpp.