Skip to main content

WsConn

Struct WsConn 

Source
struct WsConn {
    socket: WebSocket,
    state: AppState,
    engine: Arc<WshRpcEngine>,
    conn_id: String,
    priority_rx: Receiver<Value>,
    background_rx: Receiver<Value>,
    drops: Arc<LaneDrops>,
    pending_priority: VecDeque<Value>,
    bus_rx: Option<UnboundedReceiver<BusMessage>>,
    bus_agent_id: Option<String>,
}
Expand description

The egress lanes’ receivers and per-connection state that the select! loop in handle_ws_connection mutates, so each branch is a method instead of an inline block. A method returns true when the connection should end.

Fields§

§socket: WebSocket§state: AppState§engine: Arc<WshRpcEngine>§conn_id: String§priority_rx: Receiver<Value>§background_rx: Receiver<Value>§drops: Arc<LaneDrops>§pending_priority: VecDeque<Value>

Fairly-ordered priority-lane events awaiting their turn, sent one per loop iteration (on_priority_event, then flush_one_priority). Forwarding a whole drained batch inside one select! branch body would starve socket.recv() (this connection’s OWN keystrokes) for the batch, since select! re-polls siblings only when a body returns; one event per iteration keeps each send interleaved with a fresh socket.recv() poll, while the batch keeps its fair pane ordering.

§bus_rx: Option<UnboundedReceiver<BusMessage>>

Activated when a pane sends bus:register.

§bus_agent_id: Option<String>

Implementations§

Source§

impl WsConn

Source

async fn send_json(&mut self, value: &Value) -> bool

Send one JSON frame. Returns true if the send failed.

Source

async fn on_client_message( &mut self, msg: Option<Result<Message, Error>>, ) -> bool

The client’s own traffic: keystrokes and commands (wscommand), pings, close.

Source

async fn on_rpc_output(&mut self, rpc_msg: RpcMessage) -> bool

An RPC engine reply, wrapped as eventtype: rpc.

Source

async fn on_bus_message(&mut self, bus_msg: BusMessage) -> bool

A MessageBus message, for a connection registered as an agent.

Source

async fn on_priority_event(&mut self, event: Value) -> bool

Priority event lane → WebSocket. Two sources feed it:

  1. MPS Broker (via EventBusBridge) — already wrapped as { eventtype: “rpc”, data: { command: “eventrecv”, data: MuxEvent } }
  2. Direct broadcasts (e.g., SetMeta’s obj:update) — raw { eventtype: “waveobj:update”, oref: “block:xxx”, data: … } This carries terminal echo output and all interactive events.

Fairness: this lane is shared by EVERY pane on the connection, not just one. A single FIFO here means a noisy pane (heavy PTY output) can queue an unbounded number of frames ahead of a different pane’s own keystroke echo, which arrives in the same channel. Draining all immediately-available events and round-robining them by pane (see fair_drain_priority) bounds that delay to one “round” per distinct active pane instead of the length of the noisy pane’s backlog. See docs/analysis/ANALYSIS_CROSS_PANE_INPUT_DELAY_UNDER_OUTPUT_LOAD_2026_09_04.md.

Only called when pending_priority is empty: while it is still being flushed (one per iteration), the lane stays unread so we don’t pull more out of priority_rx than we have finished sending.

Source

async fn flush_one_priority(&mut self) -> bool

Flush one fairly-ordered priority event per iteration: a branch guarded on pending_priority being non-empty, see its declaration for why it is not a loop.

Source

async fn on_background_event(&mut self, first_bg: Value) -> bool

Background event lane → WebSocket. Droppable perf telemetry (sysinfo/blockstats) only; serviced when the priority lanes are momentarily idle, so it can never delay a keystroke echo.

Tradeoff of the loop’s biased;: a SUSTAINED priority-lane flood (! yes pumping terminal output) keeps the priority branches ready, so telemetry queues here until the flood pauses. The lane is bounded (BACKGROUND_LANE_CAPACITY, drop-on-full: see eventbus.rs), so a starvation long enough to fill it drops new readings instead of growing commit; fine for ~1/s telemetry. Everything immediately available is coalesced to the latest reading per (event-name:scope) key before forwarding, so the flush is at most 1 sysinfo + 1 blockstats per open block, not a burst of stale frames the browser processes back-to-back ahead of queued keypresses. See SPEC_TERMINAL_INPUT_PRIORITY_OVER_SYSINFO_2026_06_16.md §4.2.

Source

async fn report_drops(&mut self) -> bool

Tell the client about dropped events once the priority lane has drained.

Source

async fn on_ping_tick(&mut self) -> bool

Keepalive: a drop report if one is due, then a ping carrying the server time.

Source

fn close(self)

Release everything the connection registered.

Auto Trait Implementations§

§

impl !Freeze for WsConn

§

impl !RefUnwindSafe for WsConn

§

impl !Sync for WsConn

§

impl !UnwindSafe for WsConn

§

impl Send for WsConn

§

impl Unpin for WsConn

§

impl UnsafeUnpin for WsConn

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more