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.
Auto Trait Implementations§
impl !Freeze for ChannelMap
impl !RefUnwindSafe for ChannelMap
impl Send for ChannelMap
impl Sync for ChannelMap
impl Unpin for ChannelMap
impl UnsafeUnpin for ChannelMap
impl !UnwindSafe for ChannelMap
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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