fastcgi++  3.1alpha
A C++ FastCGI/Web API
Fastcgipp::Manager_base Class Referenceabstract

General task and protocol management class base. More...

#include <fastcgi++/manager.hpp>

Inheritance diagram for Fastcgipp::Manager_base:
[legend]
Collaboration diagram for Fastcgipp::Manager_base:
[legend]

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_basemakeRequest (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::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

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:

Date
August 20, 2016
Author
Eddie Carle <eddie.nosp@m.@isa.nosp@m.tec.c.nosp@m.a>

Definition at line 81 of file manager.hpp.

Constructor & Destructor Documentation

◆ Manager_base()

Fastcgipp::Manager_base::Manager_base ( unsigned  threads)

Sole constructor.

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

Definition at line 34 of file manager.cpp.

References DIAG_LOG, FAIL_LOG, and instance.

◆ ~Manager_base()

Fastcgipp::Manager_base::~Manager_base ( )

Definition at line 428 of file manager.cpp.

References DIAG_LOG.

Member Function Documentation

◆ handler()

void Fastcgipp::Manager_base::handler ( )
private

General handling function to have it's own thread.

Definition at line 254 of file manager.cpp.

Referenced by start().

Here is the caller graph for this function:

◆ join()

void Fastcgipp::Manager_base::join ( )

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 ( )
inline

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 
)
inline

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

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()

virtual std::unique_ptr<Request_base> Fastcgipp::Manager_base::makeRequest ( const Protocol::RequestId id,
const Protocol::Role role,
bool  kill 
)
protectedpure virtual

Make a request object.

Implemented in Fastcgipp::Manager< RequestT >.

◆ push()

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.

Here is the call graph for this function:

◆ resizeThreads()

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.

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)
inline

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 ( )
static

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 signalHandler().

Here is the call graph for this function:

◆ signalHandler()

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

General function to handler POSIX signals.

Definition at line 112 of file manager.cpp.

References DIAG_LOG, and WARNING_LOG.

Referenced by setupSignals().

Here is the caller graph for this function:

◆ start()

void Fastcgipp::Manager_base::start ( )

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 handler().

Here is the call graph for this function:

◆ stop()

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.

See also
join()
setupSignals()
signalHandler()

Definition at line 68 of file manager.cpp.

◆ terminate()

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.

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
staticprivate

Pointer to the Manager object.

Definition at line 289 of file manager.hpp.

Referenced by Manager_base().

◆ m_messages

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

Local messages.

Definition at line 255 of file manager.hpp.

◆ m_messagesMutex

std::mutex Fastcgipp::Manager_base::m_messagesMutex
private

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
private

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
private

Thread safe our requests.

Definition at line 252 of file manager.hpp.

◆ m_startStopMutex

std::mutex Fastcgipp::Manager_base::m_startStopMutex
private

Thread safe starting and stopping.

Definition at line 277 of file manager.hpp.

◆ m_stop

bool Fastcgipp::Manager_base::m_stop
private

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
private

Queue for pending tasks.

Definition at line 243 of file manager.hpp.

◆ m_tasksMutex

std::mutex Fastcgipp::Manager_base::m_tasksMutex
private

Thread safe our tasks.

Definition at line 246 of file manager.hpp.

◆ m_terminate

bool Fastcgipp::Manager_base::m_terminate
private

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
private

Threads our manager is running in.

Definition at line 280 of file manager.hpp.

◆ m_transceiver

Transceiver Fastcgipp::Manager_base::m_transceiver
protected

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
private

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 files: