Skip to main content

WsConn

Struct WsConn 

Source
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§

Source§

impl<S> WsConn<S>
where S: AsyncRead + AsyncWrite + Unpin + Send + 'static,

Source

pub fn new(ws: WebSocketStream<S>, allow_public_space: bool) -> Self

Creates a new WsConn from a WebSocketStream.

Trait Implementations§

Source§

impl<S> Actor for WsConn<S>
where S: AsyncRead + AsyncWrite + Unpin + Send + 'static,

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,

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,

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.

Source§

fn pre_start<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 ActorContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called once before the actor starts processing messages. Read more
Source§

fn stopping<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: &'life1 ActorContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called once after the actor’s message loop exits. Read more
Source§

fn subscribe_to_everything(&self) -> bool

Whether this actor wants to receive all messages (not just addressed to it). Used by the Multicast adapter. Read more
Source§

fn try_clone_storage(&self) -> Option<Box<dyn Actor>>

Attempts to produce a clone of this actor for storage read/write splitting. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for WsConn<S>

§

impl<S> !RefUnwindSafe for WsConn<S>

§

impl<S> !UnwindSafe for WsConn<S>

§

impl<S> Send for WsConn<S>
where S: Send,

§

impl<S> Sync for WsConn<S>
where S: Send,

§

impl<S> Unpin for WsConn<S>

§

impl<S> UnsafeUnpin for WsConn<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V