pub struct WsConn<S> { /* private fields */ }Expand description
A per-connection WebSocket actor that bridges Gun protocol messages.
Created by crate::adapters::WsServer (inbound) or
crate::adapters::OutgoingWebsocketManager (outbound). Each WsConn
manages a single WebSocket connection and translates between the
Gun wire format (text) and [Message] enum values.
A per-connection WebSocket actor that bridges Gun protocol messages.
Generic over the underlying stream type S (plain TcpStream or
TlsStream<TcpStream>). Created by crate::adapters::WsServer
(inbound) or crate::adapters::OutgoingWebsocketManager (outbound).
Each WsConn manages a single WebSocket connection and translates
between the Gun wire format (text) and [Message] enum values.
Implementations§
Trait Implementations§
Source§impl<S> Actor for WsConn<S>
impl<S> Actor for WsConn<S>
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
msg: Arc<Message>,
ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
msg: Arc<Message>,
ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Fallback single-message handler. Feeds one message then flushes.
Used when the actor runtime calls handle instead of handle_batch.
Source§fn handle_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
batch: &'life1 mut Vec<Arc<Message>>,
ctx: &'life2 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
batch: &'life1 mut Vec<Arc<Message>>,
ctx: &'life2 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Batch handler — packs all messages into a single WebSocket text frame as a JSON array, then flushes once.
Mirrors Gun.js’s peer.batch packing in mesh.say: messages
are accumulated as [{msg1},{msg2},...] and flushed as a single
WS frame, amortizing frame header overhead.
For single-message batches, the message is sent as-is (no array wrapper) — preserving backwards compatibility with peers that may not expect array frames.
§Serialized Message Cache (Sprint 1)
For Message::Put, uses [Put::get_or_serialize] to reuse
cached wire bytes. When the same Arc<Message> is relayed to
multiple peers, only the first WsConn serializes — subsequent
peers get cached bytes (refcount bump).
§Cooperative Scheduling
On current_thread runtime, we call yield_now() every 16
messages to ensure the relay’s router and other actors get
scheduled. Without this, a sender’s WsConn can starve the
relay’s receive loop, causing a deadlock.
§Frame Size Safety
If the accumulated buffer exceeds MAX_BATCH_FRAME_SIZE, we
flush early and start a new array. This prevents exceeding
WebSocket frame size limits on peers with restrictive configs.