pub struct ChannelMap { /* private fields */ }Expand description
Manages multiplexed data channels over a single WebSocket connection.
Each channel has a unique u32 ID. Client-originated channels use odd IDs, server-originated channels use even IDs to avoid collisions.
Implementations§
Source§impl ChannelMap
impl ChannelMap
Sourcepub fn new(start_id: u32) -> Self
pub fn new(start_id: u32) -> Self
Create a new ChannelMap. start_id should be 1 for clients (odd), 2 for servers (even).
Sourcepub fn alloc_id(&self) -> u32
pub fn alloc_id(&self) -> u32
Allocate the next channel ID (increments by 2 to maintain odd/even parity).
Sourcepub async fn insert(&self, channel_id: u32, sender: Sender<Bytes>)
pub async fn insert(&self, channel_id: u32, sender: Sender<Bytes>)
Register a channel with its sender.
Sourcepub async fn insert_with_tunnel(
&self,
channel_id: u32,
tunnel_id: u32,
sender: Sender<Bytes>,
)
pub async fn insert_with_tunnel( &self, channel_id: u32, tunnel_id: u32, sender: Sender<Bytes>, )
Register a channel and associate it with a tunnel_id for lifecycle tracking.
Sourcepub async fn send(&self, channel_id: u32, data: Bytes) -> bool
pub async fn send(&self, channel_id: u32, data: Bytes) -> bool
Route data to a channel. Returns false if channel not found or closed. Uses try_send so the shared WS reader never blocks on one slow channel. If the buffer is full, the channel is closed cleanly (removed + returns false).
Sourcepub async fn remove(&self, channel_id: u32)
pub async fn remove(&self, channel_id: u32)
Remove a channel and cancel any pending readiness waiter.
Sourcepub async fn close_tunnel(&self, tunnel_id: u32) -> Vec<u32>
pub async fn close_tunnel(&self, tunnel_id: u32) -> Vec<u32>
Close all channels belonging to a tunnel. Returns the channel IDs that were removed.
Sourcepub async fn wait_ready(&self, channel_id: u32) -> Receiver<()>
pub async fn wait_ready(&self, channel_id: u32) -> Receiver<()>
Register a readiness waiter for a channel.
Sourcepub async fn signal_ready(&self, channel_id: u32) -> bool
pub async fn signal_ready(&self, channel_id: u32) -> bool
Signal that a channel is ready. Returns true if a waiter was notified.