D++ (DPP)
C++ Discord API Bot Library
|
Implements a websocket client based on the SSL client. More...
#include <wsclient.h>
Public Member Functions | |
websocket_client (const std::string &hostname, const std::string &port="443", const std::string &urlpath="") | |
virtual | ~websocket_client () |
virtual void | write (const std::string &data) |
Write to websocket. Encapsulates data in frames if the status is CONNECTED. More... | |
virtual bool | handle_buffer (std::string &buffer) |
Processes incoming frames from the SSL socket input buffer. More... | |
virtual void | close () |
Close websocket. More... | |
virtual bool | HandleFrame (const std::string &buffer) |
Receives raw frame content only without headers. More... | |
virtual void | Error (uint32_t errorcode) |
Called upon error frame. More... | |
virtual void | one_second_timer () |
uint64_t | get_bytes_out () |
uint64_t | get_bytes_in () |
void | read_loop () |
Nonblocking I/O loop. 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 | Connect () |
ws_state | GetState () |
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 websocket client based on the SSL client.
dpp::websocket_client::websocket_client | ( | const std::string & | hostname, |
const std::string & | port = "443" , |
||
const std::string & | urlpath = "" |
||
) |
Connect to a specific websocket server.
hostname | Hostname to connect to |
port | Port to connect to |
urlpath | The URL path components of the HTTP request to send |
|
virtual |
Destructor
|
virtual |
Close websocket.
Reimplemented from dpp::ssl_client.
|
protectedvirtual |
(Re)connect
Reimplemented from dpp::ssl_client.
|
virtual |
Called upon error frame.
errorcode | The error code from the websocket server |
Reimplemented in dpp::discord_client, and dpp::discord_voice_client.
|
inherited |
Get total bytes received
|
inherited |
Get total bytes sent
|
protected |
Get websocket state
|
virtual |
Processes incoming frames from the SSL socket input buffer.
buffer | The buffer contents. Can modify this value removing the head elements when processed. |
Reimplemented from dpp::ssl_client.
|
virtual |
Receives raw frame content only without headers.
buffer | The buffer contents |
Reimplemented in dpp::discord_client, and dpp::discord_voice_client.
|
virtualinherited |
Log a message.
severity | severity of log message |
msg | Log message to send |
Reimplemented in dpp::discord_client.
|
virtual |
Fires every second from the underlying socket I/O loop, used for sending webscocket pings
Reimplemented from dpp::ssl_client.
Reimplemented in dpp::discord_client, and dpp::discord_voice_client.
|
inherited |
Nonblocking I/O loop.
|
virtual |
Write to websocket. Encapsulates data in frames if the status is CONNECTED.
data | The data to send. |
Reimplemented from dpp::ssl_client.
|
protectedinherited |
Input buffer received from openssl
|
protectedinherited |
Bytes in
|
protectedinherited |
Bytes out
|
protectedinherited |
SSL cipher in use
|
protectedinherited |
OpenSSL context
|
inherited |
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.
|
inherited |
This event will be called when you can read from the custom fd.
|
inherited |
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).
|
inherited |
This event will be called when you can write to a custom fd.
|
protectedinherited |
Hostname connected to
|
protectedinherited |
For timers
|
protectedinherited |
True if in nonblocking mode. The socket switches to nonblocking mode once ReadLoop is called.
|
protectedinherited |
Output buffer for sending to openssl
|
protectedinherited |
Port connected to
|
protectedinherited |
Raw file descriptor of connection
|
protectedinherited |
OpenSSL session