D++ (DPP)
C++ Discord API Bot Library
dpp::SSLClient Class Reference

Implements a simple non-blocking SSL stream client. More...

#include <sslclient.h>

+ Inheritance diagram for dpp::SSLClient:
+ Collaboration diagram for dpp::SSLClient:

Public Member Functions

uint64_t GetBytesOut ()
 
uint64_t GetBytesIn ()
 
 SSLClient (const std::string &_hostname, const std::string &_port="443")
 Connect to a specified host and port. Throws std::runtime_error on fatal error. More...
 
void ReadLoop ()
 Nonblocking I/O loop. More...
 
virtual ~SSLClient ()
 Destroy the SSLClient object. More...
 
virtual bool HandleBuffer (std::string &buffer)
 Handle input from the input buffer. More...
 
virtual void write (const std::string &data)
 Write to the output buffer. More...
 
virtual void close ()
 Close SSL connection. More...
 
virtual void log (dpp::loglevel severity, const std::string &msg)
 Log a message. More...
 

Public Attributes

std::function< int()> custom_readable_fd
 Attaching an additional file descriptor to this function will send notifications when there is data to read. More...
 
std::function< int()> custom_writeable_fd
 Attaching an additional file descriptor to this function will send notifications when you are able to write to the socket. More...
 
std::function< void()> custom_readable_ready
 This event will be called when you can read from the custom fd. More...
 
std::function< void()> custom_writeable_ready
 This event will be called when you can write to a custom fd. More...
 

Protected Member Functions

virtual void OneSecondTimer ()
 
virtual void Connect ()
 

Protected Attributes

std::string buffer
 
std::string obuffer
 
bool nonblocking
 
int sfd
 
SSL * ssl
 
SSL_CTX * ctx
 
std::string cipher
 
time_t last_tick
 
std::string hostname
 
std::string port
 
uint64_t bytes_out
 
uint64_t bytes_in
 

Detailed Description

Implements a simple non-blocking SSL stream client.

Note that although the design is non-blocking the Run() method will execute in an infinite loop until the socket disconnects. This is intended to be run within a std::thread.

Constructor & Destructor Documentation

◆ SSLClient()

dpp::SSLClient::SSLClient ( const std::string &  _hostname,
const std::string &  _port = "443" 
)

Connect to a specified host and port. Throws std::runtime_error on fatal error.

Parameters
_hostnameThe hostname to connect to
_portthe Port number to connect to

◆ ~SSLClient()

virtual dpp::SSLClient::~SSLClient ( )
virtual

Destroy the SSLClient object.

Member Function Documentation

◆ close()

virtual void dpp::SSLClient::close ( )
virtual

Close SSL connection.

Reimplemented in dpp::WSClient.

◆ Connect()

virtual void dpp::SSLClient::Connect ( )
protectedvirtual

Start connection

Reimplemented in dpp::WSClient.

◆ GetBytesIn()

uint64_t dpp::SSLClient::GetBytesIn ( )

Get total bytes received

◆ GetBytesOut()

uint64_t dpp::SSLClient::GetBytesOut ( )

Get total bytes sent

◆ HandleBuffer()

virtual bool dpp::SSLClient::HandleBuffer ( std::string &  buffer)
virtual

Handle input from the input buffer.

Parameters
bufferthe buffer content. Will be modified removing any processed front elements

Reimplemented in dpp::WSClient.

◆ log()

virtual void dpp::SSLClient::log ( dpp::loglevel  severity,
const std::string &  msg 
)
virtual

Log a message.

Parameters
severityseverity of log message
msgLog message to send

Reimplemented in dpp::DiscordClient, and dpp::DiscordVoiceClient.

◆ OneSecondTimer()

virtual void dpp::SSLClient::OneSecondTimer ( )
protectedvirtual

Called every second

Reimplemented in dpp::DiscordClient, and dpp::DiscordVoiceClient.

◆ ReadLoop()

void dpp::SSLClient::ReadLoop ( )

Nonblocking I/O loop.

◆ write()

virtual void dpp::SSLClient::write ( const std::string &  data)
virtual

Write to the output buffer.

Parameters
dataData to be written to the buffer

Reimplemented in dpp::WSClient.

Member Data Documentation

◆ buffer

std::string dpp::SSLClient::buffer
protected

Input buffer received from openssl

◆ bytes_in

uint64_t dpp::SSLClient::bytes_in
protected

Bytes in

◆ bytes_out

uint64_t dpp::SSLClient::bytes_out
protected

Bytes out

◆ cipher

std::string dpp::SSLClient::cipher
protected

SSL cipher in use

◆ ctx

SSL_CTX* dpp::SSLClient::ctx
protected

OpenSSL context

◆ custom_readable_fd

std::function<int()> dpp::SSLClient::custom_readable_fd

Attaching an additional file descriptor to this function will send notifications when there is data to read.

NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread! Returning -1 means that you don't want to be notified.

◆ custom_readable_ready

std::function<void()> dpp::SSLClient::custom_readable_ready

This event will be called when you can read from the custom fd.

◆ custom_writeable_fd

std::function<int()> dpp::SSLClient::custom_writeable_fd

Attaching an additional file descriptor to this function will send notifications when you are able to write to the socket.

NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread! You should toggle this to -1 when you do not have anything to write otherwise it'll keep triggering repeatedly (it is level triggered).

◆ custom_writeable_ready

std::function<void()> dpp::SSLClient::custom_writeable_ready

This event will be called when you can write to a custom fd.

◆ hostname

std::string dpp::SSLClient::hostname
protected

Hostname connected to

◆ last_tick

time_t dpp::SSLClient::last_tick
protected

For timers

◆ nonblocking

bool dpp::SSLClient::nonblocking
protected

True if in nonblocking mode. The socket switches to nonblocking mode once ReadLoop is called.

◆ obuffer

std::string dpp::SSLClient::obuffer
protected

Output buffer for sending to openssl

◆ port

std::string dpp::SSLClient::port
protected

Port connected to

◆ sfd

int dpp::SSLClient::sfd
protected

Raw file descriptor of connection

◆ ssl

SSL* dpp::SSLClient::ssl
protected

OpenSSL session

D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0