A websocket connection. More...
#include <websocket.h>
Classes | |
| struct | SendMessageType |
| struct | WeakWrappedMessage |
Public Member Functions | |
| 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. | |
| void | send_pong (std::string msg) override |
| Send a "Pong" message. | |
| 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. | |
| std::string | get_remote_ip () override |
| Returns the IP address the connection was opened from, also once the socket is closed (empty for a Unix domain socket). | |
| uint16_t | get_remote_port () override |
| Returns the TCP port of the remote endpoint, 0 when unavailable (Unix domain socket or socket already closed). | |
| 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 () |
Static Public Member Functions | |
| static void | create (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< void(const crow::request &, std::optional< crow::response > &, void **)> accept_handler, bool mirror_protocols, const detail::socket::tcp_socket_options &tcp_options={}) |
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. | |
| void | do_read () |
| Read a websocket message. | |
| 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. | |
| bool | finish_message () |
| Pass the complete message to the message handler and get ready for the next one. | |
| template<typename Callable > | |
| bool | call_handler (Callable &&handler) |
| Call a user handler. | |
| void | do_write () |
| Send the buffers' data through the socket. | |
| void | check_destroy (websocket::CloseStatusCode code=CloseStatusCode::ClosedAbnormally) |
| void | send_data_impl (SendMessageType *s) |
| void | send_data (int opcode, std::string &&msg) |
Static Protected Member Functions | |
| static bool | is_valid_close_code (uint16_t code) |
A websocket connection.
|
inlineprotected |
Call a user handler.
An exception escaping the handler is reported to the error handler and the connection is closed with UnexpectedCondition.
Returns false in that case, nothing more should be read from the connection.
|
inlineoverridevirtual |
Send a close signal.
Sets a flag to destroy the object once the message is sent.
Implements crow::websocket::connection.
|
inlinestatic |
Factory for a connection.
Requires a request with an "Upgrade: websocket" header.
Automatically handles the handshake.
|
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 |
Pass the complete message to the message handler and get ready for the next one.
Returns false if the handler threw, in which case the connection is being closed.
|
inlineoverridevirtual |
Returns the IP address the connection was opened from, also once the socket is closed (empty for a Unix domain socket).
Implements crow::websocket::connection.
|
inlineoverridevirtual |
Returns the TCP port of the remote endpoint, 0 when unavailable (Unix domain socket or socket already closed).
Implements crow::websocket::connection.
|
inlineoverridevirtual |
Returns the matching client/server subprotocol, empty string if none matched.
Implements crow::websocket::connection.
|
inlineprotected |
Process the payload fragment.
Unmasks the fragment, checks the opcode, merges fragments into 1 message body, and calls the appropriate handler.
|
inlinestaticprotected |
Destroy the Connection. Whether a peer may send the status code in a Close frame (RFC 6455 Section 7.4).
|
inlineoverridevirtual |
Send a binary encoded message.
Implements crow::websocket::connection.
|
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.
|
inlineoverridevirtual |
Send a plaintext message.
Implements crow::websocket::connection.
|
inlineprotected |
Send the HTTP upgrade response.
Finishes the handshake process, then starts reading messages from the socket.