D++ (DPP)
C++ Discord API Bot Library
|
Implements a simple non-blocking SSL stream client. More...
#include <sslclient.h>
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) const |
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 |
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.
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.
_hostname | The hostname to connect to |
_port | the Port number to connect to |
|
virtual |
Destroy the SSLClient object.
|
virtual |
Close SSL connection.
Reimplemented in dpp::WSClient.
|
protectedvirtual |
Start connection
Reimplemented in dpp::WSClient.
uint64_t dpp::SSLClient::GetBytesIn | ( | ) |
Get total bytes received
uint64_t dpp::SSLClient::GetBytesOut | ( | ) |
Get total bytes sent
|
virtual |
Handle input from the input buffer.
buffer | the buffer content. Will be modified removing any processed front elements |
Reimplemented in dpp::WSClient.
|
virtual |
Log a message.
severity | severity of log message |
msg | Log message to send |
Reimplemented in dpp::DiscordClient.
|
protectedvirtual |
Called every second
Reimplemented in dpp::DiscordClient, dpp::DiscordVoiceClient, and dpp::WSClient.
void dpp::SSLClient::ReadLoop | ( | ) |
Nonblocking I/O loop.
|
virtual |
Write to the output buffer.
data | Data to be written to the buffer |
Reimplemented in dpp::WSClient.
|
protected |
Input buffer received from openssl
|
protected |
Bytes in
|
protected |
Bytes out
|
protected |
SSL cipher in use
|
protected |
OpenSSL context
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.
std::function<void()> dpp::SSLClient::custom_readable_ready |
This event will be called when you can read from the custom 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).
std::function<void()> dpp::SSLClient::custom_writeable_ready |
This event will be called when you can write to a custom fd.
|
protected |
Hostname connected to
|
protected |
For timers
|
protected |
True if in nonblocking mode. The socket switches to nonblocking mode once ReadLoop is called.
|
protected |
Output buffer for sending to openssl
|
protected |
Port connected to
|
protected |
Raw file descriptor of connection
|
protected |
OpenSSL session