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="", ws_opcode opcode=OP_BINARY) | |
Connect to a specific websocket server. More... | |
virtual | ~websocket_client ()=default |
Destroy the websocket client object. More... | |
virtual void | write (const std::string_view 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 | handle_frame (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 () |
Fires every second from the underlying socket I/O loop, used for sending websocket pings. More... | |
void | send_close_packet () |
Send OP_CLOSE error code 1000 to the other side of the connection. This indicates graceful close. More... | |
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... | |
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 | |
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 | connect () |
(Re)connect More... | |
ws_state | get_state () const |
Get websocket state. 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 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 = "" , |
||
ws_opcode | opcode = OP_BINARY |
||
) |
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 |
opcode | The encoding type to use, either OP_BINARY or OP_TEXT |
|
virtualdefault |
Destroy the websocket client object.
|
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 the bytes out objectGet total bytes sent.
|
inherited |
Get SSL cipher name.
|
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, and dpp::discord_voice_client.
|
virtual |
Fires every second from the underlying socket I/O loop, used for sending websocket pings.
Reimplemented from dpp::ssl_client.
Reimplemented in dpp::discord_client, and dpp::discord_voice_client.
|
inherited |
Nonblocking I/O loop.
std::exception | Any std::exception (or derivative) thrown from read_loop() causes reconnection of the shard |
void dpp::websocket_client::send_close_packet | ( | ) |
Send OP_CLOSE error code 1000 to the other side of the connection. This indicates graceful close.
|
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 socket.
|
protectedinherited |
Bytes in.
|
protectedinherited |
Bytes out.
|
protectedinherited |
SSL cipher in use.
|
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.
|
inherited |
True if we are keeping the connection alive after it has finished.
|
protectedinherited |
For timers.
|
protectedinherited |
True if we are establishing a new connection, false if otherwise.
|
protectedinherited |
True if in nonblocking mode. The socket switches to nonblocking mode once ReadLoop is called.
|
protectedinherited |
Output buffer for sending to socket.
|
protectedinherited |
True for a plain text connection.
|
protectedinherited |
Port connected to.
|
protectedinherited |
Raw file descriptor of connection.
|
protectedinherited |
Openssl opaque contexts.