|
fastcgi++
A C++ FastCGI/Web API
|
Handles low level communication with "the other side". More...
#include <fastcgi++/transceiver.hpp>
Classes | |
| struct | Record |
| Simple FastCGI record to queue up for transmission. More... | |
Public Member Functions | |
| void | handler () |
| General transceiver handler. More... | |
| void | stop () |
| Call from any thread to stop the handler() thread. More... | |
| void | terminate () |
| Call from any thread to terminate the handler() thread. More... | |
| void | start () |
| Call from any thread to start the handler() thread. More... | |
| void | join () |
| Block until a stop() or terminate() is called and completed. More... | |
| void | send (const Socket &socket, Block &&data, bool kill) |
| Queue up a block of data for transmission. More... | |
| Transceiver (const std::function< void(Protocol::RequestId, Message &&)> sendMessage) | |
| Constructor. More... | |
| ~Transceiver () | |
| 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... | |
Private Member Functions | |
| bool | transmit () |
| Transmit all buffered data possible. More... | |
| void | receive (Socket &socket) |
| Receive data on the specified socket. More... | |
| void | cleanupSocket (const Socket &socket) |
| Cleanup a dead socket. More... | |
Private Attributes | |
| std::map< Socket, Block > | m_receiveBuffers |
| Container associating sockets with their receive buffers. More... | |
| std::deque< std::unique_ptr< Record > > | m_sendBuffer |
| Buffer for transmitting data More... | |
| std::mutex | m_sendBufferMutex |
| Thread safe the send buffer. More... | |
| const std::function< void(Protocol::RequestId, Message &&)> | m_sendMessage |
| Function to call to pass messages to requests. More... | |
| SocketGroup | m_sockets |
| Listen for connections with this. More... | |
| std::atomic_bool | m_terminate |
| True when handler() should be terminating. More... | |
| std::atomic_bool | m_stop |
| True when handler() should be stopping. More... | |
| std::thread | m_thread |
| Thread our handler is running in. More... | |
Handles low level communication with "the other side".
This class handles the sending/receiving/buffering of data through the OS level sockets and also the creation/destruction of the sockets themselves.
Definition at line 58 of file transceiver.hpp.
| Fastcgipp::Transceiver::Transceiver | ( | const std::function< void(Protocol::RequestId, Message &&)> | sendMessage | ) |
Constructor.
Construct a transceiver object based on an initial file descriptor to listen on and a function to pass messages on to.
| [in] | sendMessage | Function to call to pass messages to requests |
Definition at line 120 of file transceiver.cpp.
References DIAG_LOG.
| Fastcgipp::Transceiver::~Transceiver | ( | ) |
Definition at line 224 of file transceiver.cpp.
References DIAG_LOG.
|
private |
Cleanup a dead socket.
Definition at line 193 of file transceiver.cpp.
References Fastcgipp::Protocol::badFcgiId, and Fastcgipp::Socket::close().
| void Fastcgipp::Transceiver::handler | ( | ) |
General transceiver handler.
This function is called by Manager::handler() to both transmit data passed to it from requests and relay received data back to them as a Message. The function will return true if there is nothing at all for it to do.
Definition at line 75 of file transceiver.cpp.
Referenced by start().
| void Fastcgipp::Transceiver::join | ( | ) |
Block until a stop() or terminate() is called and completed.
Definition at line 112 of file transceiver.cpp.
|
inline |
Listen to the default Fastcgi socket.
Calling this simply adds the default socket used on FastCGI applications that are initialized from HTTP servers.
Definition at line 128 of file transceiver.hpp.
References Fastcgipp::SocketGroup::listen(), and m_sockets.
Referenced by Fastcgipp::Manager_base::listen().
|
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.
| [in] | name | Name of socket (path in Unix world). |
| [in] | permissions | Permissions of socket. If you do not wish to set the permissions, leave it as it's default value of 0xffffffffUL. |
| [in] | owner | Owner (username) of socket. Leave as nullptr if you do not wish to set it. |
| [in] | group | Group (group name) of socket. Leave as nullptr if you do not wish to set it. |
Definition at line 148 of file transceiver.hpp.
References Fastcgipp::SocketGroup::listen(), and m_sockets.
|
inline |
Listen to a TCP port.
Listen on a specific interface and TCP port.
| [in] | interface | Interface to listen on. This could be an IP address or a hostname. If you don't want to specify the interface, pass nullptr. |
| [in] | service | Port or service to listen on. This could be a service name, or a string representation of a port number. |
Definition at line 169 of file transceiver.hpp.
References Fastcgipp::SocketGroup::listen(), and m_sockets.
|
inlineprivate |
Receive data on the specified socket.
Definition at line 134 of file transceiver.cpp.
References Fastcgipp::Block::begin(), Fastcgipp::Message::data, Fastcgipp::Logging::header(), Fastcgipp::Socket::read(), Fastcgipp::Block::reserve(), Fastcgipp::Block::size(), and Fastcgipp::Socket::valid().
Queue up a block of data for transmission.
| [in] | socket | Socket to write the data out |
| [in] | data | Block of data to send out |
| [in] | kill | True if the socket should be closed once everything is sent. |
Definition at line 205 of file transceiver.cpp.
Referenced by Fastcgipp::Manager< RequestT >::makeRequest().
| void Fastcgipp::Transceiver::start | ( | ) |
Call from any thread to start the handler() thread.
If the thread is already running this will do nothing.
Definition at line 100 of file transceiver.cpp.
References handler().
| void Fastcgipp::Transceiver::stop | ( | ) |
Call from any thread to stop the handler() thread.
Calling this thread will signal the handler() thread to cleanly stop itself. This means it keeps going until all connections are closed. No new connections are accepted.
Definition at line 88 of file transceiver.cpp.
| void Fastcgipp::Transceiver::terminate | ( | ) |
Call from any thread to terminate the handler() thread.
Calling this thread will signal the handler() thread to immediately terminate itself. This means it doesn't wait until all connections are closed.
Definition at line 94 of file transceiver.cpp.
|
inlineprivate |
Transmit all buffered data possible.
Definition at line 32 of file transceiver.cpp.
References Fastcgipp::Socket::close(), Fastcgipp::Transceiver::Record::data, Fastcgipp::Block::end(), Fastcgipp::Transceiver::Record::kill, m_receiveBuffers, m_sendBuffer, m_sendBufferMutex, Fastcgipp::Transceiver::Record::read, Fastcgipp::Transceiver::Record::socket, and Fastcgipp::Socket::write().
Container associating sockets with their receive buffers.
Definition at line 178 of file transceiver.hpp.
Referenced by transmit().
|
private |
Buffer for transmitting data
Definition at line 200 of file transceiver.hpp.
Referenced by transmit().
|
private |
Thread safe the send buffer.
Definition at line 203 of file transceiver.hpp.
Referenced by transmit().
|
private |
Function to call to pass messages to requests.
Definition at line 206 of file transceiver.hpp.
|
private |
Listen for connections with this.
Definition at line 209 of file transceiver.hpp.
Referenced by listen().
|
private |
True when handler() should be stopping.
Definition at line 224 of file transceiver.hpp.
|
private |
True when handler() should be terminating.
Definition at line 221 of file transceiver.hpp.
|
private |
Thread our handler is running in.
Definition at line 227 of file transceiver.hpp.
1.8.14