fastcgi++  3.1alpha
A C++ FastCGI/Web API
Fastcgipp::Manager< RequestT > Class Template Reference

General task and protocol management class. More...

#include <fastcgi++/manager.hpp>

Inheritance diagram for Fastcgipp::Manager< RequestT >:
[legend]
Collaboration diagram for Fastcgipp::Manager< RequestT >:
[legend]

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...
 
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 Attributes

Transceiver m_transceiver
 Handles low level communication with the other side. More...
 

Private Member Functions

std::unique_ptr< Request_basemakeRequest (const Protocol::RequestId &id, const Protocol::Role &role, bool kill)
 Make a request object. More...
 
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::RequestIdm_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_baseinstance =nullptr
 Pointer to the Manager object. More...
 

Detailed Description

template<class RequestT>
class Fastcgipp::Manager< RequestT >

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:

Template Parameters
RequestTA class type derived from the Request class with at least the Request::response() function defined.
Date
May 13, 2016
Author
Eddie Carle <eddie.nosp@m.@isa.nosp@m.tec.c.nosp@m.a>

Definition at line 321 of file manager.hpp.

Constructor & Destructor Documentation

◆ Manager()

template<class RequestT >
Fastcgipp::Manager< RequestT >::Manager ( unsigned  threads = std::thread::hardware_concurrency())
inline

Sole constructor.

Parameters
[in]threadsNumber of threads to use for request handling

Definition at line 328 of file manager.hpp.

Member Function Documentation

◆ handler()

void Fastcgipp::Manager_base::handler ( )
privateinherited

General handling function to have it's own thread.

Definition at line 254 of file manager.cpp.

Referenced by Fastcgipp::Manager_base::start().

Here is the caller graph for this function:

◆ join()

void Fastcgipp::Manager_base::join ( )
inherited

Block until a stop() or terminate() is called and completed.

Definition at line 91 of file manager.cpp.

◆ listen() [1/3]

bool Fastcgipp::Manager_base::listen ( )
inlineinherited

Listen to the default Fastcgi socket.

Calling this simply adds the default socket used on FastCGI applications that are initialized from HTTP servers.

Returns
True on success. False on failure.

Definition at line 159 of file manager.hpp.

◆ listen() [2/3]

bool Fastcgipp::Manager_base::listen ( const char *  interface,
const char *  service 
)
inlineinherited

Listen to a TCP port.

Listen on a specific interface and TCP port.

Parameters
[in]interfaceInterface to listen on. This could be an IP address or a hostname. If you don't want to specify the interface, pass nullptr.
[in]servicePort or service to listen on. This could be a service name, or a string representation of a port number.
Returns
True on success. False on failure.

Definition at line 200 of file manager.hpp.

◆ listen() [3/3]

bool Fastcgipp::Manager_base::listen ( const char *  name,
uint32_t  permissions = 0xffffffffUL,
const char *  owner = nullptr,
const char *  group = nullptr 
)
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.

Parameters
[in]nameName of socket (path in Unix world).
[in]permissionsPermissions of socket. If you do not wish to set the permissions, leave it as it's default value of 0xffffffffUL.
[in]ownerOwner (username) of socket. Leave as nullptr if you do not wish to set it.
[in]groupGroup (group name) of socket. Leave as nullptr if you do not wish to set it.
Returns
True on success. False on failure.

Definition at line 179 of file manager.hpp.

◆ localHandler()

◆ makeRequest()

template<class RequestT >
std::unique_ptr<Request_base> Fastcgipp::Manager< RequestT >::makeRequest ( const Protocol::RequestId id,
const Protocol::Role role,
bool  kill 
)
inlineprivatevirtual

Make a request object.

Implements Fastcgipp::Manager_base.

Definition at line 334 of file manager.hpp.

◆ push()

void Fastcgipp::Manager_base::push ( Protocol::RequestId  id,
Message &&  message 
)
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::Protocol::BeginRequest::role, and WARNING_LOG.

Here is the call graph for this function:

◆ resizeThreads()

void Fastcgipp::Manager_base::resizeThreads ( unsigned  threads)
inherited

Call before start to change the number of threads.

If the Manager is already running this will do nothing.

Parameters
[in]threadsNumber of threads to use for request handling
See also
Manager_base()
start()

Definition at line 417 of file manager.cpp.

◆ reuseAddress()

void Fastcgipp::Manager_base::reuseAddress ( bool  value)
inlineinherited

Should we set socket option to reuse address.

Parameters
[in]statusSet to true if you want to reuse address. False otherwise (default).

Definition at line 215 of file manager.hpp.

◆ setupSignals()

void Fastcgipp::Manager_base::setupSignals ( )
staticinherited

Configure the handlers for POSIX signals.

By calling this function appropriate handlers will be set up for SIGPIPE, SIGUSR1 and SIGTERM.

See also
signalHandler()

Definition at line 100 of file manager.cpp.

References Fastcgipp::Manager_base::signalHandler().

Here is the call graph for this function:

◆ signalHandler()

void Fastcgipp::Manager_base::signalHandler ( int  signum)
staticprivateinherited

General function to handler POSIX signals.

Definition at line 112 of file manager.cpp.

References DIAG_LOG, and WARNING_LOG.

Referenced by Fastcgipp::Manager_base::setupSignals().

Here is the caller graph for this function:

◆ start()

void Fastcgipp::Manager_base::start ( )
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, and Fastcgipp::Manager_base::handler().

Here is the call graph for this function:

◆ stop()

void Fastcgipp::Manager_base::stop ( )
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.

See also
join()
setupSignals()
signalHandler()

Definition at line 68 of file manager.cpp.

◆ terminate()

void Fastcgipp::Manager_base::terminate ( )
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.

See also
join()
setupSignals()
signalHandler()

Definition at line 60 of file manager.cpp.

Member Data Documentation

◆ instance

Fastcgipp::Manager_base * Fastcgipp::Manager_base::instance =nullptr
staticprivateinherited

Pointer to the Manager object.

Definition at line 289 of file manager.hpp.

Referenced by Fastcgipp::Manager_base::Manager_base().

◆ m_messages

std::queue<std::pair<Message, Socket> > Fastcgipp::Manager_base::m_messages
privateinherited

Local messages.

Definition at line 255 of file manager.hpp.

◆ m_messagesMutex

std::mutex Fastcgipp::Manager_base::m_messagesMutex
privateinherited

Thread safe our local messages.

Definition at line 258 of file manager.hpp.

◆ m_requests

Protocol::Requests<std::unique_ptr<Request_base> > Fastcgipp::Manager_base::m_requests
privateinherited

An associative container for our requests.

Definition at line 249 of file manager.hpp.

◆ m_requestsMutex

std::shared_timed_mutex Fastcgipp::Manager_base::m_requestsMutex
privateinherited

Thread safe our requests.

Definition at line 252 of file manager.hpp.

◆ m_startStopMutex

std::mutex Fastcgipp::Manager_base::m_startStopMutex
privateinherited

Thread safe starting and stopping.

Definition at line 277 of file manager.hpp.

◆ m_stop

bool Fastcgipp::Manager_base::m_stop
privateinherited

True when the manager should be stopping.

Definition at line 274 of file manager.hpp.

◆ m_tasks

std::queue<Protocol::RequestId> Fastcgipp::Manager_base::m_tasks
privateinherited

Queue for pending tasks.

Definition at line 243 of file manager.hpp.

◆ m_tasksMutex

std::mutex Fastcgipp::Manager_base::m_tasksMutex
privateinherited

Thread safe our tasks.

Definition at line 246 of file manager.hpp.

◆ m_terminate

bool Fastcgipp::Manager_base::m_terminate
privateinherited

True when the manager should be terminating.

Definition at line 271 of file manager.hpp.

◆ m_threads

std::vector<std::thread> Fastcgipp::Manager_base::m_threads
privateinherited

Threads our manager is running in.

Definition at line 280 of file manager.hpp.

◆ m_transceiver

Transceiver Fastcgipp::Manager_base::m_transceiver
protectedinherited

Handles low level communication with the other side.

Definition at line 239 of file manager.hpp.

◆ m_wake

std::condition_variable Fastcgipp::Manager_base::m_wake
privateinherited

Condition variable to wake handler() threads up.

Definition at line 283 of file manager.hpp.


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