![]() |
D++ (DPP)
C++ Discord API Bot Library
|
Listens on a TCP socket for new connections, and whenever a new connection is received, accept it and spawn a new connection of type T. More...
#include <socket_listener.h>
Public Member Functions | |
socket_listener (cluster *owner, const std::string_view address, uint16_t port, socket_listener_type type=li_plaintext, const std::string &private_key="", const std::string &public_key="") | |
Create a new socket listener (TCP server) More... | |
~socket_listener () | |
Destructor, detaches on_socket_close event. More... | |
virtual void | handle_accept (socket sfd, const struct socket_events &e) |
Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid. More... | |
virtual void | emplace (socket newfd)=0 |
Emplace a new connection into the connection map for the server. This is a factory function which must be implemented by the deriving class. More... | |
Public Attributes | |
raii_socket | fd |
The listening socket for incoming connections. More... | |
std::unordered_map< socket, std::unique_ptr< T > > | connections |
Active connections for the server of type T. More... | |
cluster * | creator {nullptr} |
Cluster creator. More... | |
bool | plaintext {true} |
True if plain text connections to the server are allowed. More... | |
std::string | private_key_file |
Private key PEM file path, if running an SSL server. More... | |
std::string | public_key_file |
Public key PEM file path, if running an SSL server. More... | |
event_handle | close_event |
Event to handle socket removal from the connection map. More... | |
socket_events | events |
Socket events for listen socket in the socket engine. More... | |
Listens on a TCP socket for new connections, and whenever a new connection is received, accept it and spawn a new connection of type T.
T | type for socket connection, must be derived from ssl_connection |
|
inline |
Create a new socket listener (TCP server)
owner | Owning cluster |
address | IP address to bind the listening socket to, use 0.0.0.0 to bind all interfaces |
port | Port number to bind the listening socket to |
type | Type of server, plaintext or SSL |
private_key | For SSL servers, a path to the PEM private key file |
public_key | For SSL servers, a path to the PEM public key file |
connection_exception | on failure to bind or listen to the port/interface |
|
inline |
Destructor, detaches on_socket_close event.
|
pure virtual |
Emplace a new connection into the connection map for the server. This is a factory function which must be implemented by the deriving class.
newfd | File descriptor for new connection |
Implemented in dpp::http_server.
|
inlinevirtual |
Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid.
sfd | File descriptor for listening socket |
e | socket events for the listening socket |
event_handle dpp::socket_listener< T, typename >::close_event |
Event to handle socket removal from the connection map.
std::unordered_map<socket, std::unique_ptr<T> > dpp::socket_listener< T, typename >::connections |
Active connections for the server of type T.
cluster* dpp::socket_listener< T, typename >::creator {nullptr} |
Cluster creator.
socket_events dpp::socket_listener< T, typename >::events |
Socket events for listen socket in the socket engine.
raii_socket dpp::socket_listener< T, typename >::fd |
The listening socket for incoming connections.
bool dpp::socket_listener< T, typename >::plaintext {true} |
True if plain text connections to the server are allowed.
std::string dpp::socket_listener< T, typename >::private_key_file |
Private key PEM file path, if running an SSL server.
std::string dpp::socket_listener< T, typename >::public_key_file |
Public key PEM file path, if running an SSL server.