fastcgi++
A C++ FastCGI/Web API
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Fastcgipp::Manager_base Class Referenceabstract

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

#include <fastcgi++/manager.hpp>

Inheritance diagram for Fastcgipp::Manager_base:
Fastcgipp::Manager< RequestT >

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

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 63 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 417 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().

◆ 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 124 of file manager.hpp.

References Fastcgipp::Transceiver::listen(), and m_transceiver.

◆ listen() [2/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 144 of file manager.hpp.

References Fastcgipp::Transceiver::listen(), and m_transceiver.

◆ listen() [3/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 165 of file manager.hpp.

References Fastcgipp::Transceiver::listen(), and m_transceiver.

◆ localHandler()

void Fastcgipp::Manager_base::localHandler ( )
inlineprivate

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

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

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

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

◆ 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 233 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 199 of file manager.hpp.

◆ m_messagesMutex

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

Thread safe our local messages.

Definition at line 202 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 193 of file manager.hpp.

◆ m_requestsMutex

std::shared_timed_mutex Fastcgipp::Manager_base::m_requestsMutex
private

Thread safe our requests.

Definition at line 196 of file manager.hpp.

◆ m_startStopMutex

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

Thread safe starting and stopping.

Definition at line 221 of file manager.hpp.

◆ m_stop

bool Fastcgipp::Manager_base::m_stop
private

True when the manager should be stopping.

Definition at line 218 of file manager.hpp.

◆ m_tasks

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

Queue for pending tasks.

Definition at line 187 of file manager.hpp.

◆ m_tasksMutex

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

Thread safe our tasks.

Definition at line 190 of file manager.hpp.

◆ m_terminate

bool Fastcgipp::Manager_base::m_terminate
private

True when the manager should be terminating.

Definition at line 215 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 224 of file manager.hpp.

◆ m_transceiver

Transceiver Fastcgipp::Manager_base::m_transceiver
protected

Handles low level communication with the other side.

Definition at line 183 of file manager.hpp.

Referenced by listen(), and Fastcgipp::Manager< RequestT >::makeRequest().

◆ m_wake

std::condition_variable Fastcgipp::Manager_base::m_wake
private

Condition variable to wake handler() threads up.

Definition at line 227 of file manager.hpp.


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