17#include <system_error>
90 std::function<
void(std::error_code)> handler) -> void;
100 auto async_accept(std::function<
void(std::error_code)> handler) -> void;
120 std::function<
void(std::error_code, std::size_t)> handler)
134 std::function<
void(std::error_code, std::size_t)> handler)
147 std::function<
void(std::error_code)> handler) -> void;
160 std::function<
void(std::error_code)> handler) -> void;
196 std::function<
void(
const std::vector<uint8_t>&)> callback) -> void;
207 std::function<
void(
const std::vector<uint8_t>&)> callback) -> void;
218 std::function<
void(
ws_close_code,
const std::string&)> callback) -> void;
WebSocket protocol handler for message processing.
WebSocket framing layer built on top of tcp_socket.
std::function< void(ws_close_code, const std::string &)> close_callback_
auto is_open() const -> bool
Checks if the connection is open and ready.
std::function< void(const ws_message &)> message_callback_
auto state() const -> ws_state
Gets the current connection state.
auto handle_protocol_ping(const std::vector< uint8_t > &payload) -> void
Handles a ping frame from the protocol layer.
std::shared_ptr< tcp_socket > tcp_socket_
auto set_error_callback(std::function< void(std::error_code)> callback) -> void
Sets the callback for errors.
auto async_send_binary(std::vector< uint8_t > &&data, std::function< void(std::error_code, std::size_t)> handler) -> VoidResult
Sends a binary message.
auto async_handshake(const std::string &host, const std::string &path, uint16_t port, std::function< void(std::error_code)> handler) -> void
Performs WebSocket client handshake (RFC 6455 Section 4.1).
~websocket_socket()
Destructor.
auto handle_protocol_message(const ws_message &msg) -> void
Handles a decoded message from the protocol layer.
auto on_tcp_receive(std::span< const uint8_t > data) -> void
Called by tcp_socket when data is received.
std::mutex callback_mutex_
auto set_close_callback(std::function< void(ws_close_code, const std::string &)> callback) -> void
Sets the callback for received close frames.
websocket_socket(std::shared_ptr< tcp_socket > socket, bool is_client)
Constructs a websocket_socket wrapping an existing tcp_socket.
auto start_read() -> void
Starts reading WebSocket frames from the underlying socket.
auto async_accept(std::function< void(std::error_code)> handler) -> void
Accepts WebSocket server handshake (RFC 6455 Section 4.2).
std::function< void(const std::vector< uint8_t > &)> pong_callback_
websocket_protocol protocol_
std::atomic< ws_state > state_
auto handle_protocol_close(ws_close_code code, const std::string &reason) -> void
Handles a close frame from the protocol layer.
auto async_send_text(std::string &&message, std::function< void(std::error_code, std::size_t)> handler) -> VoidResult
Sends a text message (UTF-8 encoded).
auto async_send_ping(std::vector< uint8_t > payload, std::function< void(std::error_code)> handler) -> void
Sends a ping control frame.
auto set_message_callback(std::function< void(const ws_message &)> callback) -> void
Sets the callback for received messages.
std::function< void(const std::vector< uint8_t > &)> ping_callback_
auto async_close(ws_close_code code, const std::string &reason, std::function< void(std::error_code)> handler) -> void
Initiates the WebSocket closing handshake.
std::function< void(std::error_code)> error_callback_
auto on_tcp_error(std::error_code ec) -> void
Called by tcp_socket when an error occurs.
auto set_ping_callback(std::function< void(const std::vector< uint8_t > &)> callback) -> void
Sets the callback for received ping frames.
auto set_pong_callback(std::function< void(const std::vector< uint8_t > &)> callback) -> void
Sets the callback for received pong frames.
auto handle_protocol_pong(const std::vector< uint8_t > &payload) -> void
Handles a pong frame from the protocol layer.
::kcenon::network::VoidResult VoidResult
ws_state
WebSocket connection state (RFC 6455 Section 7).
@ open
Connection established and ready.
@ connecting
Handshake in progress.
ws_close_code
WebSocket close status codes (RFC 6455 Section 7.4).
@ closed
Connection terminated.
@ closing
CONNECTION_CLOSE sent, waiting for timeout.
Network-specific error and result type definitions.
Represents a complete WebSocket message.