A websocket connection. More...
#include <websocket.h>
Classes | |
struct | SendMessageType |
struct | WeakWrappedMessage |
Public Member Functions | |
Connection (const crow::request &req, Adaptor &&adaptor, Handler *handler, uint64_t max_payload, const std::vector< std::string > &subprotocols, std::function< void(crow::websocket::connection &)> open_handler, std::function< void(crow::websocket::connection &, const std::string &, bool)> message_handler, std::function< void(crow::websocket::connection &, const std::string &, uint16_t)> close_handler, std::function< void(crow::websocket::connection &, const std::string &)> error_handler, std::function< bool(const crow::request &, void **)> accept_handler) | |
Constructor for a connection. More... | |
template<typename CompletionHandler > | |
void | dispatch (CompletionHandler &&handler) |
Send data through the socket. | |
template<typename CompletionHandler > | |
void | post (CompletionHandler &&handler) |
Send data through the socket and return immediately. | |
void | send_ping (std::string msg) override |
Send a "Ping" message. More... | |
void | send_pong (std::string msg) override |
Send a "Pong" message. More... | |
void | send_binary (std::string msg) override |
Send a binary encoded message. | |
void | send_text (std::string msg) override |
Send a plaintext message. | |
void | close (std::string const &msg, uint16_t status_code) override |
Send a close signal. More... | |
std::string | get_remote_ip () override |
void | set_max_payload_size (uint64_t payload) |
std::string | get_subprotocol () const override |
Returns the matching client/server subprotocol, empty string if none matched. | |
Public Member Functions inherited from crow::websocket::connection | |
void | userdata (void *u) |
void * | userdata () |
Protected Member Functions | |
std::string | build_header (int opcode, size_t size) |
Generate the websocket headers using an opcode and the message size (in bytes). | |
void | start (std::string &&hello) |
Send the HTTP upgrade response. More... | |
void | do_read () |
Read a websocket message. More... | |
bool | is_FIN () |
Check if the FIN bit is set. | |
int | opcode () |
Extract the opcode from the header. | |
bool | handle_fragment () |
Process the payload fragment. More... | |
void | do_write () |
Send the buffers' data through the socket. More... | |
void | check_destroy (websocket::CloseStatusCode code=CloseStatusCode::ClosedAbnormally) |
Destroy the Connection. | |
void | send_data_impl (SendMessageType *s) |
void | send_data (int opcode, std::string &&msg) |
A websocket connection.
|
inline |
Constructor for a connection.
Requires a request with an "Upgrade: websocket" header.
Automatically handles the handshake.
|
inlineoverridevirtual |
Send a close signal.
Sets a flag to destroy the object once the message is sent.
Implements crow::websocket::connection.
|
inlineprotected |
Read a websocket message.
Involves:
Handling headers (opcodes, size).
Unmasking the payload.
Reading the actual payload.
|
inlineprotected |
Send the buffers' data through the socket.
Also destroys the object if the Close flag is set.
|
inlineprotected |
Process the payload fragment.
Unmasks the fragment, checks the opcode, merges fragments into 1 message body, and calls the appropriate handler.
|
inlineoverridevirtual |
Send a "Ping" message.
Usually invoked to check if the other point is still online.
Implements crow::websocket::connection.
|
inlineoverridevirtual |
Send a "Pong" message.
Usually automatically invoked as a response to a "Ping" message.
Implements crow::websocket::connection.
|
inlineprotected |
Send the HTTP upgrade response.
Finishes the handshake process, then starts reading messages from the socket.