32#include <condition_variable>
69 static std::unique_ptr<WebSocketChannel>
connect(
70 std::unique_ptr<TcpStream> tcp,
71 std::string_view
host,
72 std::string_view path =
"/",
79 static std::unique_ptr<WebSocketChannel>
accept(
80 std::unique_ptr<TcpStream> tcp,
86 bool send(
const std::uint8_t* data, std::size_t size)
override;
99 enum class Role : uint8_t { Client, Server };
104 bool send_frame(uint8_t opcode,
const std::uint8_t* data, std::size_t size);
106 void fire_error(std::string_view reason);
108 void dispatch(std::function<
void()> task);
110 std::unique_ptr<TcpStream> tcp_;
114 mutable std::mutex mutex_;
115 std::mutex write_mutex_;
116 std::atomic<bool> open_{
false};
117 std::atomic<bool> closed_fired_{
false};
MessageChannel(const MessageChannel &)=delete
Definition websocket_channel.hpp:64
static std::unique_ptr< WebSocketChannel > connect(std::unique_ptr< TcpStream > tcp, std::string_view host, std::string_view path="/", WebSocketOptions options={})
Perform a client handshake over tcp, then start the reader.
bool send(const std::uint8_t *data, std::size_t size) override
Send a message.
~WebSocketChannel() override
void close() override
Close the channel. Idempotent. Fires the closed callback.
bool is_open() const override
Whether the channel is currently usable.
void on_message(MessageCallback callback) override
Install / replace callbacks.
void on_closed(ChannelClosedCallback callback) override
bool send_text(std::string_view text) override
static std::unique_ptr< WebSocketChannel > accept(std::unique_ptr< TcpStream > tcp, WebSocketOptions options={})
Perform a server-side handshake over an already-accepted tcp connection.
static std::string compute_accept_key(std::string_view client_key)
Expose the handshake Sec-WebSocket-Accept for debugging and for tests that want to verify RFC 6455 co...
void on_error(ChannelErrorCallback callback) override
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
Definition generated_event_source.hpp:33
std::function< void()> ChannelClosedCallback
Called once when the channel transitions to a closed state — either the peer closed,...
Definition message_channel.hpp:55
std::function< void(const Message &message)> MessageCallback
Called when the channel receives a complete message.
Definition message_channel.hpp:51
std::function< void(std::string_view reason)> ChannelErrorCallback
Called when a transport-level error occurs.
Definition message_channel.hpp:60
std::function< void(std::function< void()>)> MessageExecutor
Executor used to dispatch callbacks off whichever worker thread the channel runs internally.
Definition message_channel.hpp:64
Options for WebSocketChannel construction.
Definition websocket_channel.hpp:44
std::size_t max_payload
Maximum inbound payload size (bytes).
Definition websocket_channel.hpp:54
MessageExecutor executor
Executor used to dispatch on_message, on_closed, on_error.
Definition websocket_channel.hpp:49
std::size_t max_message
Maximum total size (bytes) of a message reassembled across continuation frames.
Definition websocket_channel.hpp:61