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 — feeds all messages into the WS frame buffer without
flushing. Because flush_threshold is set to usize::MAX, feed()
never triggers an implicit flush and never blocks on I/O.
Flushing is handled by a dedicated background task spawned in
pre_start, which calls flush() on a timer. This decouples the
actor’s message processing from socket I/O — the actor never
suspends waiting for the TCP buffer to drain.
§Cooperative Scheduling
On current_thread runtime, feed() with flush_threshold(MAX)
completes without suspending, so a full batch of 64 messages can
be processed without yielding to other tasks. We call
yield_now() every 16 messages to ensure the relay’s router and
other actors get scheduled. Without this, on current_thread, a
sender’s WsConn can starve the relay’s receive loop, causing a
deadlock where the relay never processes incoming puts.