NuriaProject Framework  0.1
The NuriaProject Framework
Signals | Public Member Functions | Protected Member Functions | Friends | List of all members
Nuria::FastCgiBackend Class Reference

FastCGI integration for HttpServer. More...

#include <fastcgibackend.hpp>

Inheritance diagram for Nuria::FastCgiBackend:
Nuria::HttpBackend

Signals

void connectionAdded ()
 
void connectionClosed ()
 

Public Member Functions

 FastCgiBackend (HttpServer *server)
 
 ~FastCgiBackend () override
 
int currentConnectionCount () const
 
QMap< QByteArray, QByteArray > customConfiguration () const
 
bool isListening () const
 
bool isSecure () const
 
bool listen ()
 
bool listen (int port, const QHostAddress &iface=QHostAddress::Any)
 
bool listenLocal (const QString &name, QLocalServer::SocketOptions options=QLocalServer::NoOptions)
 
bool listenLocal (qintptr handle)
 
int maxConcurrentConnections () const
 
int maxConcurrentRequests () const
 
int port () const
 
void setCustomConfiguration (const QByteArray &name, const QByteArray &value)
 
void setMaxConcurrentConnections (int count)
 
void setMaxConcurrentRequests (int count) const
 
void stop ()
 
- Public Member Functions inherited from Nuria::HttpBackend
 HttpBackend (HttpServer *server)
 
 ~HttpBackend ()
 
HttpServerhttpServer () const
 

Protected Member Functions

void serverThreadCreated (QThread *thread) override
 

Friends

class Internal::FastCgiThreadObject
 

Detailed Description

FastCGI integration for HttpServer.

This class provides a FastCGI backend for HttpServer. Using this you can write FastCGI servers easily.

Note
This implementation only supports writing FCGI responders.
Usage

This implementation supports both, opening a TCP socket which the front-end HTTP server pushes requests to or inheriting the socket opened by the front-end server from the FCGI_LISTENSOCK_FILENO environment variable.

FastCGI parameter

FastCGI front-end servers pass "parameters" to FastCGI applications to tell them about incoming connections. These are comparable to environment variables or HTTP headers.

The following parameters are needed by FastCgiBackend:

Parameters whose name begin with "HTTP_" are stripped of that prefix. All FastCGI parameters are forwarded to the HttpClient and can be accessed by HttpClient::requestHeader(), with names are converted from "THIS_FORMAT" to "This-Format". Example:

client->requestHeader ("Some-Thing"); // Access the SOME_THING FCGI parameter
client->requestHeader ("Host"); // Access the HTTP_HOST FCGI parameter
A note on logging

You should think about where to put your logs. Some front-end servers support receiving log messages through the standard output or error streams. Whatever you choose, if you need to change the default logging target, see Debug::setDestination().

Behaviour in high-load scenarios

It should be pointed out that all tested front-end HTTP servers, namely lighttpd and nginx, work equally well with this implementation in normal circumstances. Though it should be noted that benchmarking showed that nginx is inferior to lighttpd one. With about 1k concurrent requests done by the benchmarking utility, nginx suffered from having issues serving the last ca. 10% of all requests. Lighttpd does not have this restriction.

These restriction do not apply when configuring both servers to act as a HTTP proxy and relying on the NuriaFrameworks HTTP implementation.

Constructor & Destructor Documentation

Nuria::FastCgiBackend::FastCgiBackend ( HttpServer server)
explicit

Constructor.

Nuria::FastCgiBackend::~FastCgiBackend ( )
override

Destructor.

Member Function Documentation

void Nuria::FastCgiBackend::connectionAdded ( )
signal

The FastCGI front-end server has opened a new connection to the back-end.

void Nuria::FastCgiBackend::connectionClosed ( )
signal

The FastCGI front-end server has closed a connection.

Note
Don't connect to this signal using Qt::DirectConnection.
int Nuria::FastCgiBackend::currentConnectionCount ( ) const

Returns the count of connections currently opened by the FastCGI front-end server.

QMap< QByteArray, QByteArray > Nuria::FastCgiBackend::customConfiguration ( ) const

Returns teh custom configuration map.

bool Nuria::FastCgiBackend::isListening ( ) const
virtual

Returns true if the server is currently listening for connections.

Implements Nuria::HttpBackend.

bool Nuria::FastCgiBackend::isSecure ( ) const
virtual

Returns true if this back-end uses secure connections. The default implementation returns false.

Reimplemented from Nuria::HttpBackend.

bool Nuria::FastCgiBackend::listen ( )

Start listening on the socket forwarded to this process. This is mainly there for front-end servers

bool Nuria::FastCgiBackend::listen ( int  port,
const QHostAddress &  iface = QHostAddress::Any 
)

Listen for TCP connections on port and iface.

bool Nuria::FastCgiBackend::listenLocal ( const QString &  name,
QLocalServer::SocketOptions  options = QLocalServer::NoOptions 
)

Listens on name using a QLocalServer.

bool Nuria::FastCgiBackend::listenLocal ( qintptr  handle)

Listens on handle using a QLocalServer.

int Nuria::FastCgiBackend::maxConcurrentConnections ( ) const

Returns the max amount of concurrent connections. Defaults to the count of CPU cores of the host machine.

int Nuria::FastCgiBackend::maxConcurrentRequests ( ) const

Returns the max amount of concurrent requests. Defaults to: (count of CPU cores) * 10

int Nuria::FastCgiBackend::port ( ) const
virtual

Returns the port this server is listening on, or -1 if it's not listening.

Implements Nuria::HttpBackend.

void Nuria::FastCgiBackend::serverThreadCreated ( QThread *  thread)
overrideprotectedvirtual

Called by the HttpServer when a new server thread has been created. This lets back-ends register their own thread-specific bookkeeping routines.

This function will also be called by the HttpServer if no multi-threading is used. In this case, the function will be called once with thread being the one the server is associated with.

To run some kind of initialization after the thread has been started, use one of:

QTimer::singleShot (0, object, SLOT(...)); // Pre Qt5.4
QTimer::singleShot (0, object, &Object::...); // Qt5.4 and up
QTimer::singleShot (0, []() { ... }); // Qt5.4 and up
Note
The function is called in the thread the HttpServer lives in.

The default implementation does nothing.

Reimplemented from Nuria::HttpBackend.

void Nuria::FastCgiBackend::setCustomConfiguration ( const QByteArray &  name,
const QByteArray &  value 
)

Sets a custom configuration field for FastCGI front-end servers. This field will be sent to the FCGI server after receiving a FCGI_GET_VALUES request.

If there's already a configuration for name, it will be overriden.

void Nuria::FastCgiBackend::setMaxConcurrentConnections ( int  count)

Sets the max amount of concurrent connections.

void Nuria::FastCgiBackend::setMaxConcurrentRequests ( int  count) const

Sets the max amount of concurrent requests.

void Nuria::FastCgiBackend::stop ( )

Stops listening immediately.


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