pub struct CompressedWebSocketStream<S> { /* private fields */ }Expand description
A WebSocket stream with permessage-deflate compression (RFC 7692)
This type mirrors WebSocketStream but uses CompressedProtocol for
automatic compression/decompression of messages.
Implementations§
Source§impl<S> CompressedWebSocketStream<S>
impl<S> CompressedWebSocketStream<S>
Sourcepub fn server(inner: S, config: Config, deflate_config: DeflateConfig) -> Self
pub fn server(inner: S, config: Config, deflate_config: DeflateConfig) -> Self
Create a new compressed WebSocket stream for server role
Sourcepub fn client(inner: S, config: Config, deflate_config: DeflateConfig) -> Self
pub fn client(inner: S, config: Config, deflate_config: DeflateConfig) -> Self
Create a new compressed WebSocket stream for client role
Sourcepub fn is_backpressured(&self) -> bool
pub fn is_backpressured(&self) -> bool
Check if backpressure should be applied
Sourcepub fn write_buffer_len(&self) -> usize
pub fn write_buffer_len(&self) -> usize
Get the current write buffer length
Source§impl<S> CompressedWebSocketStream<S>
impl<S> CompressedWebSocketStream<S>
Sourcepub fn split(self) -> (CompressedSplitReader<S>, CompressedSplitWriter<S>)
pub fn split(self) -> (CompressedSplitReader<S>, CompressedSplitWriter<S>)
Split the compressed WebSocket stream into separate read and write halves
This allows TRUE concurrent reading and writing from different tasks with ZERO lock contention. The underlying TCP stream is split at the OS level for maximum performance.
Both halves maintain compression/decompression state independently:
- Reader has the decoder for decompressing incoming messages
- Writer has the encoder for compressing outgoing messages
§Example
ⓘ
let (mut reader, mut writer) = compressed_ws.split();
// Read in one task - NEVER blocks writer
tokio::spawn(async move {
while let Some(msg) = reader.next().await {
println!("Got: {:?}", msg);
}
});
// Write in another - NEVER blocks reader
writer.send(Message::Text("Hello".into())).await?;Trait Implementations§
Source§impl<S> Sink<Message> for CompressedWebSocketStream<S>
Available on crate feature permessage-deflate only.
impl<S> Sink<Message> for CompressedWebSocketStream<S>
Available on crate feature
permessage-deflate only.Source§fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<()>>
Attempts to prepare the
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<()>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<()>
Begin the process of sending a value to the sink.
Each call to this function must be preceded by a successful call to
poll_ready which returned Poll::Ready(Ok(())). Read moreSource§impl<S> Stream for CompressedWebSocketStream<S>
Available on crate feature permessage-deflate only.
impl<S> Stream for CompressedWebSocketStream<S>
Available on crate feature
permessage-deflate only.impl<'__pin, S> Unpin for CompressedWebSocketStream<S>where
PinnedFieldsOf<__Origin<'__pin, S>>: Unpin,
Auto Trait Implementations§
impl<S> Freeze for CompressedWebSocketStream<S>where
S: Freeze,
impl<S> RefUnwindSafe for CompressedWebSocketStream<S>where
S: RefUnwindSafe,
impl<S> Send for CompressedWebSocketStream<S>where
S: Send,
impl<S> Sync for CompressedWebSocketStream<S>where
S: Sync,
impl<S> UnwindSafe for CompressedWebSocketStream<S>where
S: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more