|
fastcgi++
A C++ FastCGI/Web API
|
Class for representing an OS level socket that listens for connections. More...
#include <fastcgi++/sockets.hpp>
Public Member Functions | |
| SocketGroup () | |
| ~SocketGroup () | |
| 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... | |
| Socket | connect (const char *name) |
| Connect to a named socket. More... | |
| Socket | connect (const char *host, const char *service) |
| Connect to a host on a TCP port/serivce. More... | |
| Socket | poll (bool block) |
| Poll socket set for new incoming connections and data. More... | |
| void | wake () |
| Wake up from a nap inside poll() More... | |
| size_t | size () const |
| How many active sockets (not counting listeners) are in the group. More... | |
| void | accept (bool status) |
| Should we accept new connections? More... | |
Private Member Functions | |
| void | createSocket (const socket_t listener) |
| Accept a new connection and create it's socket. More... | |
| bool | pollAdd (const socket_t socket) |
| Add a socket identifier to the poll list. More... | |
| bool | pollDel (const socket_t socket) |
| Remove a socket identifier to the poll list. More... | |
Private Attributes | |
| std::set< socket_t > | m_listeners |
| These are the sockets we listen for connections on. More... | |
| poll_t | m_poll |
| Our poll object. More... | |
| socket_t | m_wakeSockets [2] |
| A pair of sockets for wakeup purposes. More... | |
| bool | m_waking |
| Set to true while there is a pending wake. More... | |
| std::atomic_bool | m_accept |
| Set to true if we should be accepting new connections. More... | |
| std::atomic_bool | m_refreshListeners |
| Set to true if we should refresh the listeners in the poll. More... | |
| std::mutex | m_wakingMutex |
| We need this mutex to thread safe the wake() function. More... | |
| std::map< socket_t, Socket > | m_sockets |
| All the sockets. More... | |
| std::deque< std::string > | m_filenames |
| Filenames to cleanup when we're done. More... | |
Friends | |
| class | Socket |
| Our sockets need access to our private data. More... | |
Class for representing an OS level socket that listens for connections.
It works together with the Socket class to establish all the interfacing between the OS and the Transceiver class to communicate with the outside world. The object of this class represents the socket that listens for incoming connections to the FastCGI server. This class will create and manage an array of Socket objects as new connections are initiated.
The only part of this class that is safe to call from multiple threads is the wake() function.
Definition at line 287 of file sockets.hpp.
| Fastcgipp::SocketGroup::SocketGroup | ( | ) |
Definition at line 149 of file sockets.cpp.
References DIAG_LOG, m_wakeSockets, and pollAdd().
| Fastcgipp::SocketGroup::~SocketGroup | ( | ) |
Definition at line 171 of file sockets.cpp.
References DIAG_LOG.
| void Fastcgipp::SocketGroup::accept | ( | bool | status | ) |
Should we accept new connections?
| [in] | status | Set to false if you want to start refusing new connections. True otherwise (default). |
Definition at line 696 of file sockets.cpp.
| Fastcgipp::Socket Fastcgipp::SocketGroup::connect | ( | const char * | name | ) |
Connect to a named socket.
Connect to 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). |
Definition at line 363 of file sockets.cpp.
References ERROR_LOG.
| Fastcgipp::Socket Fastcgipp::SocketGroup::connect | ( | const char * | host, |
| const char * | service | ||
| ) |
Connect to a host on a TCP port/serivce.
| [in] | host | Host to connect to. This could be an IP address address or a hostname. |
| [in] | service | Port or service to connect to. This could be a service name, or a string representation of a port number. |
Definition at line 397 of file sockets.cpp.
References ERROR_LOG.
|
inlineprivate |
Accept a new connection and create it's socket.
Definition at line 609 of file sockets.cpp.
| bool Fastcgipp::SocketGroup::listen | ( | ) |
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 201 of file sockets.cpp.
References ERROR_LOG.
Referenced by Fastcgipp::Transceiver::listen().
| bool Fastcgipp::SocketGroup::listen | ( | const char * | name, |
| uint32_t | permissions = 0xffffffffUL, |
||
| const char * | owner = nullptr, |
||
| const char * | group = nullptr |
||
| ) |
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 226 of file sockets.cpp.
References ERROR_LOG.
| bool Fastcgipp::SocketGroup::listen | ( | const char * | interface, |
| const char * | service | ||
| ) |
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 306 of file sockets.cpp.
References ERROR_LOG.
| Fastcgipp::Socket Fastcgipp::SocketGroup::poll | ( | bool | block | ) |
Poll socket set for new incoming connections and data.
Calling this will initiate a poll for both new connections and new incoming data within the set of sockets that this object has created. It will also keep an eye out for dead sockets and tear them down accordingly.
Its behaviour is as follows:
This function can be either blocking or non-blocking depending on the boolean value passed to it. If the call is blocking it can be awoken in a thread safe manner with a call to wake().
| [in] | block | Set true to make the call sleep and wait for new data to arrive. |
Definition at line 460 of file sockets.cpp.
References ERROR_LOG, FAIL_LOG, and WARNING_LOG.
|
private |
Add a socket identifier to the poll list.
Definition at line 651 of file sockets.cpp.
Referenced by Fastcgipp::Socket::Socket(), and SocketGroup().
|
private |
Remove a socket identifier to the poll list.
Definition at line 676 of file sockets.cpp.
|
inline |
How many active sockets (not counting listeners) are in the group.
Definition at line 406 of file sockets.hpp.
References m_sockets.
| void Fastcgipp::SocketGroup::wake | ( | ) |
Wake up from a nap inside poll()
Calling this simply wakes up the execution thread that poll() is blocking in. If there is no nap taking place, calling this does nothing.
This function is thread safe and can be called from anywhere as often as is desired.
Definition at line 596 of file sockets.cpp.
References FAIL_LOG.
|
friend |
Our sockets need access to our private data.
Definition at line 420 of file sockets.hpp.
|
private |
Set to true if we should be accepting new connections.
Definition at line 435 of file sockets.hpp.
|
private |
Filenames to cleanup when we're done.
Definition at line 456 of file sockets.hpp.
|
private |
These are the sockets we listen for connections on.
Definition at line 423 of file sockets.hpp.
|
private |
Our poll object.
Definition at line 426 of file sockets.hpp.
|
private |
Set to true if we should refresh the listeners in the poll.
Definition at line 438 of file sockets.hpp.
|
private |
A pair of sockets for wakeup purposes.
Definition at line 429 of file sockets.hpp.
Referenced by SocketGroup().
|
private |
Set to true while there is a pending wake.
Definition at line 432 of file sockets.hpp.
|
private |
We need this mutex to thread safe the wake() function.
Definition at line 441 of file sockets.hpp.
1.8.14