![]() |
D++ (DPP)
C++ Discord API Bot Library
|
Implements a websocket client based on the SSL client. More...
#include <wsclient.h>
Inheritance diagram for dpp::websocket_client:
Collaboration diagram for dpp::websocket_client:Public Member Functions | |
| websocket_client (const std::string &hostname, const std::string &port="443", const std::string &urlpath="") | |
| virtual | ~websocket_client () |
| virtual void | close () |
| Close websocket. More... | |
| virtual void | Error (uint32_t errorcode) |
| Called upon error frame. More... | |
| uint64_t | get_bytes_in () |
| uint64_t | get_bytes_out () |
| std::string | get_cipher () |
| virtual bool | handle_buffer (std::string &buffer) |
| Processes incoming frames from the SSL socket input buffer. More... | |
| virtual bool | HandleFrame (const std::string &buffer) |
| Receives raw frame content only without headers. More... | |
| virtual void | log (dpp::loglevel severity, const std::string &msg) const |
| Log a message. More... | |
| virtual void | one_second_timer () |
| void | read_loop () |
| Nonblocking I/O loop. More... | |
| virtual void | write (const std::string &data) |
| Write to websocket. Encapsulates data in frames if the status is CONNECTED. More... | |
Public Attributes | |
| std::function< dpp::socket()> | custom_readable_fd |
| Attaching an additional file descriptor to this function will send notifications when there is data to read. More... | |
| std::function< void()> | custom_readable_ready |
| This event will be called when you can read from the custom fd. More... | |
| std::function< dpp::socket()> | 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_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 |
| uint64_t | bytes_in |
| uint64_t | bytes_out |
| std::string | cipher |
| std::string | hostname |
| time_t | last_tick |
| bool | nonblocking |
| std::string | obuffer |
| std::string | port |
| dpp::socket | sfd |
| opensslcontext * | ssl |
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
|
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 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
|
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 opaque contexts