| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::socket_listener< T, typename > Struct Template Referenceabstract

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

Inheritance diagram for dpp::socket_listener< T, typename >:
[legend]
Collaboration diagram for dpp::socket_listener< T, typename >:
[legend]

## 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).
| ~socket_listener ()
| Destructor, detaches on_socket_close event.
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.
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.

## Public Attributes

event_handle | close_event
| Event to handle socket removal from the connection map.
std::unordered_map< socket, std::unique_ptr< T > > | connections
| Active connections for the server of type T.
cluster * | creator {nullptr}
| Cluster creator.
socket_events | events
| Socket events for listen socket in the socket engine.
raii_socket | fd
| The listening socket for incoming connections.
bool | plaintext {true}
| True if plain text connections to the server are allowed.
std::string | private_key_file
| Private key PEM file path, if running an SSL server.
std::string | public_key_file
| Public key PEM file path, if running an SSL server.

## Detailed Description

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>
struct dpp::socket_listener< T, typename >

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.

Template Parameters

  T | type for socket connection, must be derived from ssl_connection

## Constructor & Destructor Documentation

## ◆ socket_listener()

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

dpp::socket_listener< T, typename >::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 = "" )

inline

Create a new socket listener (TCP server).

Parameters

  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

Exceptions

  connection_exception | on failure to bind or listen to the port/interface

## ◆ ~socket_listener()

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

dpp::socket_listener< T, typename >::~socket_listener | ( |  | ) |

inline

Destructor, detaches on_socket_close event.

## Member Function Documentation

## ◆ emplace()

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

virtual void dpp::socket_listener< T, typename >::emplace | ( | socket | newfd | ) |

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.

Parameters

  newfd | File descriptor for new connection

Implemented in dpp::http_server.

## ◆ handle_accept()

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

virtual void dpp::socket_listener< T, typename >::handle_accept | ( | socket | sfd,
|  | const struct socket_events & | e )

inline virtual

Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid.

Parameters

  sfd | File descriptor for listening socket
  e | socket events for the listening socket

## Member Data Documentation

## ◆ close_event

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

event_handle dpp::socket_listener< T, typename >::close_event

Event to handle socket removal from the connection map.

## ◆ connections

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

std::unordered_map<socket, std::unique_ptr<T> > dpp::socket_listener< T, typename >::connections

Active connections for the server of type T.

## ◆ creator

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

cluster* dpp::socket_listener< T, typename >::creator {nullptr}

Cluster creator.

## ◆ events

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

socket_events dpp::socket_listener< T, typename >::events

Socket events for listen socket in the socket engine.

## ◆ fd

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

raii_socket dpp::socket_listener< T, typename >::fd

The listening socket for incoming connections.

## ◆ plaintext

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

bool dpp::socket_listener< T, typename >::plaintext {true}

True if plain text connections to the server are allowed.

## ◆ private_key_file

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

std::string dpp::socket_listener< T, typename >::private_key_file

Private key PEM file path, if running an SSL server.

## ◆ public_key_file

template<typename T, typename = std::enable_if_t<std::is_base_of_v<ssl_connection, T>>>

std::string dpp::socket_listener< T, typename >::public_key_file

Public key PEM file path, if running an SSL server.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0