D++ (DPP)
C++ Discord API Bot Library
|
Implements a simple non-blocking SSL stream client. More...
#include <sslclient.h>
Public Member Functions | |
uint64_t | get_bytes_out () |
Get the bytes out objectGet total bytes sent. More... | |
uint64_t | get_bytes_in () |
Get total bytes received. More... | |
std::string | get_cipher () |
Get SSL cipher name. More... | |
ssl_client (const std::string &_hostname, const std::string &_port="443", bool plaintext_downgrade=false, bool reuse=false) | |
Connect to a specified host and port. Throws std::runtime_error on fatal error. More... | |
void | read_loop () |
Nonblocking I/O loop. More... | |
virtual | ~ssl_client () |
Destroy the ssl_client object. More... | |
virtual bool | handle_buffer (std::string &buffer) |
Handle input from the input buffer. This function will be called until all data in the buffer has been processed and the buffer is empty. More... | |
virtual void | write (const std::string_view data) |
Write to the output buffer. More... | |
virtual void | close () |
Close socket connection. More... | |
virtual void | log (dpp::loglevel severity, const std::string &msg) const |
Log a message. More... | |
Public Attributes | |
socket_callback_t | custom_readable_fd |
Attaching an additional file descriptor to this function will send notifications when there is data to read. More... | |
socket_callback_t | custom_writeable_fd |
Attaching an additional file descriptor to this function will send notifications when you are able to write to the socket. More... | |
socket_notification_t | custom_readable_ready |
This event will be called when you can read from the custom fd. More... | |
socket_notification_t | custom_writeable_ready |
This event will be called when you can write to a custom fd. More... | |
bool | keepalive |
True if we are keeping the connection alive after it has finished. More... | |
Protected Member Functions | |
virtual void | one_second_timer () |
Called every second. More... | |
virtual void | connect () |
Start SSL connection and connect to TCP endpoint. More... | |
Protected Attributes | |
std::string | buffer |
Input buffer received from socket. More... | |
std::string | obuffer |
Output buffer for sending to socket. More... | |
bool | nonblocking |
True if in nonblocking mode. The socket switches to nonblocking mode once ReadLoop is called. More... | |
dpp::socket | sfd |
Raw file descriptor of connection. More... | |
openssl_connection * | ssl |
Openssl opaque contexts. More... | |
std::string | cipher |
SSL cipher in use. More... | |
time_t | last_tick |
For timers. More... | |
std::string | hostname |
Hostname connected to. More... | |
std::string | port |
Port connected to. More... | |
uint64_t | bytes_out |
Bytes out. More... | |
uint64_t | bytes_in |
Bytes in. More... | |
bool | plaintext |
True for a plain text connection. More... | |
bool | make_new |
True if we are establishing a new connection, false if otherwise. More... | |
Implements a simple non-blocking SSL stream client.
dpp::ssl_client::ssl_client | ( | const std::string & | _hostname, |
const std::string & | _port = "443" , |
||
bool | plaintext_downgrade = false , |
||
bool | reuse = false |
||
) |
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 |
plaintext_downgrade | Set to true to connect using plaintext only, without initialising SSL. |
reuse | Attempt to reuse previous connections for this hostname and port, if available Note that no Discord endpoints will function when downgraded. This option is provided only for connection to non-Discord addresses such as within dpp::cluster::request(). |
dpp::exception | Failed to initialise connection |
|
virtual |
Destroy the ssl_client object.
|
virtual |
Close socket connection.
Reimplemented in dpp::https_client, and dpp::websocket_client.
|
protectedvirtual |
Start SSL connection and connect to TCP endpoint.
dpp::exception | Failed to initialise connection |
Reimplemented in dpp::https_client, and dpp::websocket_client.
uint64_t dpp::ssl_client::get_bytes_in | ( | ) |
Get total bytes received.
uint64_t dpp::ssl_client::get_bytes_out | ( | ) |
Get the bytes out objectGet total bytes sent.
std::string dpp::ssl_client::get_cipher | ( | ) |
Get SSL cipher name.
|
virtual |
Handle input from the input buffer. This function will be called until all data in the buffer has been processed and the buffer is empty.
buffer | the buffer content. Will be modified removing any processed front elements |
Reimplemented in dpp::https_client, and dpp::websocket_client.
|
virtual |
Log a message.
severity | severity of log message |
msg | Log message to send |
Reimplemented in dpp::discord_client, and dpp::discord_voice_client.
|
protectedvirtual |
Called every second.
Reimplemented in dpp::discord_client, dpp::discord_voice_client, dpp::https_client, and dpp::websocket_client.
void dpp::ssl_client::read_loop | ( | ) |
Nonblocking I/O loop.
std::exception | Any std::exception (or derivative) thrown from read_loop() causes reconnection of the shard |
|
virtual |
Write to the output buffer.
data | Data to be written to the buffer. |
Reimplemented in dpp::websocket_client.
|
protected |
Input buffer received from socket.
|
protected |
Bytes in.
|
protected |
Bytes out.
|
protected |
SSL cipher in use.
socket_callback_t dpp::ssl_client::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.
socket_notification_t dpp::ssl_client::custom_readable_ready |
This event will be called when you can read from the custom fd.
socket_callback_t dpp::ssl_client::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).
socket_notification_t dpp::ssl_client::custom_writeable_ready |
This event will be called when you can write to a custom fd.
|
protected |
Hostname connected to.
bool dpp::ssl_client::keepalive |
True if we are keeping the connection alive after it has finished.
|
protected |
For timers.
|
protected |
True if we are establishing a new connection, false if otherwise.
|
protected |
True if in nonblocking mode. The socket switches to nonblocking mode once ReadLoop is called.
|
protected |
Output buffer for sending to socket.
|
protected |
True for a plain text connection.
|
protected |
Port connected to.
|
protected |
Raw file descriptor of connection.
|
protected |
Openssl opaque contexts.