Represents an active WebSocket connection.
More...
#include <WebSocketConnection.hpp>
|
| struct | Transport |
| | Where frames go. Lets the protocol logic run without a socket (tests). More...
|
| |
|
| | WebSocketConnection (server::Connection &underlying_connection, bool enable_deflate=false) |
| |
| | WebSocketConnection (Transport transport, bool enable_deflate=false) |
| |
| | ~WebSocketConnection () |
| |
| void | on_message (std::function< void(const std::string &)> handler) |
| | Registers a callback to be called when a message is received.
|
| |
| void | on_binary_message (std::function< void(const std::string &)> handler) |
| | Registers a callback for binary messages. When set, binary messages go here and on_message() receives only text; when not set, on_message() receives both, as before.
|
| |
| void | on_close (std::function< void()> handler) |
| | Registers a callback to be called when the connection is closed.
|
| |
| void | send (const std::string &message) |
| | Sends a text message over the WebSocket connection. Safe to call from any thread.
|
| |
| void | send_binary (const std::string &data) |
| | Sends a binary message. Safe to call from any thread.
|
| |
| void | close (uint16_t status_code=1000) |
| | Closes the WebSocket connection gracefully.
|
| |
| void | ping () |
| |
| void | handle_transport_closed () |
| | Internal: the underlying transport has gone away (peer disconnect, timeout or I/O error). Fires the close handler once, if it has not already run, and makes further send() calls no-ops.
|
| |
| void | set_max_message_size (size_t bytes) |
| | Sets the largest message payload accepted from the client, after decompression. Larger messages close the connection with 1009.
|
| |
| const HttpRequest * | handshake_request () const |
| | The HTTP request that opened this WebSocket: path, query, headers, cookies, and whatever the route's middleware set on it (user from jwt_auth(), session, ...).
|
| |
| void | set_handshake_request (const HttpRequest *request) |
| | Set by the server around the handler call.
|
| |
| void | process_raw_data (std::vector< char > &buffer) |
| |
Represents an active WebSocket connection.
◆ WebSocketConnection() [1/2]
| orbit::http::websocket::WebSocketConnection::WebSocketConnection |
( |
server::Connection & |
underlying_connection, |
|
|
bool |
enable_deflate = false |
|
) |
| |
|
explicit |
◆ WebSocketConnection() [2/2]
| orbit::http::websocket::WebSocketConnection::WebSocketConnection |
( |
Transport |
transport, |
|
|
bool |
enable_deflate = false |
|
) |
| |
|
explicit |
◆ ~WebSocketConnection()
| orbit::http::websocket::WebSocketConnection::~WebSocketConnection |
( |
| ) |
|
◆ cleanup_streams()
| void orbit::http::websocket::WebSocketConnection::cleanup_streams |
( |
| ) |
|
|
private |
◆ close()
| void orbit::http::websocket::WebSocketConnection::close |
( |
uint16_t |
status_code = 1000 | ) |
|
Closes the WebSocket connection gracefully.
◆ deflate_payload()
| std::string orbit::http::websocket::WebSocketConnection::deflate_payload |
( |
const std::string & |
payload | ) |
|
|
private |
◆ deliver_message()
| bool orbit::http::websocket::WebSocketConnection::deliver_message |
( |
uint8_t |
opcode, |
|
|
bool |
compressed, |
|
|
std::string |
payload |
|
) |
| |
|
private |
◆ fail_connection()
| void orbit::http::websocket::WebSocketConnection::fail_connection |
( |
uint16_t |
status_code | ) |
|
|
private |
◆ handle_close_frame()
| void orbit::http::websocket::WebSocketConnection::handle_close_frame |
( |
const std::string & |
payload | ) |
|
|
private |
◆ handle_transport_closed()
| void orbit::http::websocket::WebSocketConnection::handle_transport_closed |
( |
| ) |
|
Internal: the underlying transport has gone away (peer disconnect, timeout or I/O error). Fires the close handler once, if it has not already run, and makes further send() calls no-ops.
◆ handshake_request()
| const HttpRequest * orbit::http::websocket::WebSocketConnection::handshake_request |
( |
| ) |
const |
|
inline |
The HTTP request that opened this WebSocket: path, query, headers, cookies, and whatever the route's middleware set on it (user from jwt_auth(), session, ...).
Available only while the route's handler runs (EventRouter's on_connect included); null afterwards. Copy what the connection needs to keep, such as the user id, into its own state.
◆ inflate_payload()
| bool orbit::http::websocket::WebSocketConnection::inflate_payload |
( |
const std::string & |
payload, |
|
|
std::string & |
out |
|
) |
| |
|
private |
◆ init_streams()
| void orbit::http::websocket::WebSocketConnection::init_streams |
( |
| ) |
|
|
private |
◆ on_binary_message()
| void orbit::http::websocket::WebSocketConnection::on_binary_message |
( |
std::function< void(const std::string &)> |
handler | ) |
|
Registers a callback for binary messages. When set, binary messages go here and on_message() receives only text; when not set, on_message() receives both, as before.
◆ on_close()
| void orbit::http::websocket::WebSocketConnection::on_close |
( |
std::function< void()> |
handler | ) |
|
Registers a callback to be called when the connection is closed.
- Parameters
-
| handler | The callback function. |
◆ on_message()
| void orbit::http::websocket::WebSocketConnection::on_message |
( |
std::function< void(const std::string &)> |
handler | ) |
|
Registers a callback to be called when a message is received.
- Parameters
-
| handler | The callback function. |
◆ ping()
| void orbit::http::websocket::WebSocketConnection::ping |
( |
| ) |
|
Sends a ping; the peer's pong is ordinary traffic, so it keeps an idle timeout from closing a healthy connection.
◆ process_raw_data()
| void orbit::http::websocket::WebSocketConnection::process_raw_data |
( |
std::vector< char > & |
buffer | ) |
|
◆ send()
| void orbit::http::websocket::WebSocketConnection::send |
( |
const std::string & |
message | ) |
|
◆ send_binary()
| void orbit::http::websocket::WebSocketConnection::send_binary |
( |
const std::string & |
data | ) |
|
Sends a binary message. Safe to call from any thread.
◆ send_frame()
| void orbit::http::websocket::WebSocketConnection::send_frame |
( |
uint8_t |
opcode, |
|
|
const std::string & |
payload |
|
) |
| |
|
private |
◆ set_handshake_request()
| void orbit::http::websocket::WebSocketConnection::set_handshake_request |
( |
const HttpRequest * |
request | ) |
|
|
inline |
Set by the server around the handler call.
◆ set_max_message_size()
| void orbit::http::websocket::WebSocketConnection::set_max_message_size |
( |
size_t |
bytes | ) |
|
|
inline |
Sets the largest message payload accepted from the client, after decompression. Larger messages close the connection with 1009.
- Parameters
-
| bytes | Limit in bytes (default 16 MiB). |
◆ write_frame_locked()
| void orbit::http::websocket::WebSocketConnection::write_frame_locked |
( |
uint8_t |
first_byte, |
|
|
const std::string & |
payload |
|
) |
| |
|
private |
◆ binary_handler_
| std::function<void(const std::string&)> orbit::http::websocket::WebSocketConnection::binary_handler_ |
|
private |
◆ close_handler_
| std::function<void()> orbit::http::websocket::WebSocketConnection::close_handler_ |
|
private |
◆ deflate_enabled_
| bool orbit::http::websocket::WebSocketConnection::deflate_enabled_ {false} |
|
private |
◆ deflate_stream_
| z_stream orbit::http::websocket::WebSocketConnection::deflate_stream_ {} |
|
private |
◆ fragment_compressed_
| bool orbit::http::websocket::WebSocketConnection::fragment_compressed_ {false} |
|
private |
◆ fragment_opcode_
| uint8_t orbit::http::websocket::WebSocketConnection::fragment_opcode_ {0} |
|
private |
◆ fragment_payload_
| std::string orbit::http::websocket::WebSocketConnection::fragment_payload_ |
|
private |
◆ handshake_request_
| const HttpRequest* orbit::http::websocket::WebSocketConnection::handshake_request_ {nullptr} |
|
private |
◆ inflate_stream_
| z_stream orbit::http::websocket::WebSocketConnection::inflate_stream_ {} |
|
private |
◆ is_closed_
| std::atomic<bool> orbit::http::websocket::WebSocketConnection::is_closed_ {false} |
|
private |
◆ max_message_size_
| size_t orbit::http::websocket::WebSocketConnection::max_message_size_ {16 * 1024 * 1024} |
|
private |
◆ message_handler_
| std::function<void(const std::string&)> orbit::http::websocket::WebSocketConnection::message_handler_ |
|
private |
◆ send_mutex_
| std::mutex orbit::http::websocket::WebSocketConnection::send_mutex_ |
|
private |
◆ streams_initialized_
| bool orbit::http::websocket::WebSocketConnection::streams_initialized_ {false} |
|
private |
◆ transport_
| Transport orbit::http::websocket::WebSocketConnection::transport_ |
|
private |
The documentation for this class was generated from the following file: