Struct BlockingClientWebSocket
pub struct BlockingClientWebSocket { /* private fields */ }http and std and ws only.Expand description
A connected blocking client WebSocket and its HTTP handshake metadata.
Implementations§
§impl BlockingClientWebSocket
impl BlockingClientWebSocket
pub fn response(&self) -> &Parts
pub fn response(&self) -> &Parts
View the original response data from which this WebSocket was created.
pub fn accepted_protocol(&self) -> Option<&str>
pub fn accepted_protocol(&self) -> Option<&str>
Return the subprotocol accepted during the HTTP handshake, if any.
pub fn send_message(&mut self, message: Message) -> Result<(), ProtocolError>
pub fn send_message(&mut self, message: Message) -> Result<(), ProtocolError>
Write and immediately flush a message.
pub fn recv_message(&mut self) -> Result<Message, ProtocolError>
pub fn recv_message(&mut self) -> Result<Message, ProtocolError>
Read the next message.
pub fn into_inner(self) -> WebSocket<Io<Upgraded>>
pub fn into_inner(self) -> WebSocket<Io<Upgraded>>
Consume this wrapper and return the blocking WebSocket.
pub fn into_parts(
self,
) -> (WebSocket<Io<Upgraded>>, Parts, Option<AcceptedWebSocketProtocol>)
pub fn into_parts( self, ) -> (WebSocket<Io<Upgraded>>, Parts, Option<AcceptedWebSocketProtocol>)
Consume this wrapper into its socket and handshake metadata.
Methods from Deref<Target = WebSocket<Io<Upgraded>>>§
pub fn get_mut(&mut self) -> &mut Stream
pub fn get_mut(&mut self) -> &mut Stream
Returns a mutable reference to the inner stream.
pub fn set_config(&mut self, set_func: impl FnOnce(&mut WebSocketConfig))
pub fn set_config(&mut self, set_func: impl FnOnce(&mut WebSocketConfig))
Change the configuration.
§Panics
Panics if config is invalid e.g. max_write_buffer_size <= write_buffer_size.
pub fn get_config(&self) -> &WebSocketConfig
pub fn get_config(&self) -> &WebSocketConfig
Read the configuration.
pub fn can_read(&self) -> bool
pub fn can_read(&self) -> bool
Check if it is possible to read messages.
Reading is impossible after receiving Message::Close. It is still possible after
sending close frame since the peer still may send some data before confirming close.
pub fn can_write(&self) -> bool
pub fn can_write(&self) -> bool
Check if it is possible to write messages.
Writing gets impossible immediately after sending or receiving Message::Close.
pub fn read(&mut self) -> Result<Message, ProtocolError>
pub fn read(&mut self) -> Result<Message, ProtocolError>
Read a message from stream, if possible.
This will also queue responses to ping and close messages. These responses
will be written and flushed on the next call to read,
write or flush.
§Closing the connection
When the remote endpoint decides to close the connection this will return the close message with an optional close frame.
You should continue calling read, write or
flush to drive the reply to the close frame until ProtocolError::Io (close)
is returned. Once that happens it is safe to drop the underlying connection.
pub fn send(&mut self, message: Message) -> Result<(), ProtocolError>
pub fn send(&mut self, message: Message) -> Result<(), ProtocolError>
pub fn write(&mut self, message: Message) -> Result<(), ProtocolError>
pub fn write(&mut self, message: Message) -> Result<(), ProtocolError>
Write a message to the provided stream, if possible.
A subsequent call should be made to flush to flush writes.
In the event of stream write failure the message frame will be stored
in the write buffer and will try again on the next call to write
or flush.
If the write buffer would exceed the configured WebSocketConfig::max_write_buffer_size
Err(WriteBufferFull(msg_frame)) is returned.
This call will generally not flush. However, if there are queued automatic messages they will be written and eagerly flushed.
For example, upon receiving ping messages this crate queues pong replies automatically.
The next call to read, write or flush
will write & flush the pong reply. This means you should not respond to ping frames manually.
You can however send pong frames manually in order to indicate a unidirectional heartbeat
as described in RFC 6455. Note that
if read returns a ping, you should flush before passing
a custom pong to write, otherwise the automatic queued response to the
ping will not be sent as it will be replaced by your custom pong message.
§Errors
- If the WebSocket’s write buffer is full,
ProtocolError::WriteBufferFullwill be returned along with the equivalent passed message frame. - If the connection is closed and should be dropped, this will return
ProtocolError::Io(close). - If you try again after
ProtocolError::Io(close) was returned either from here or fromread,ProtocolError::Iowith reason will be returned. This indicates a program error on your part. ProtocolError::Iois returned if the underlying connection returns an error (consider these fatal except for WouldBlock).ProtocolError::Ioif your message size is bigger than the configured max message size.
pub fn flush(&mut self) -> Result<(), ProtocolError>
pub fn flush(&mut self) -> Result<(), ProtocolError>
Flush writes.
Ensures all messages previously passed to write and automatic
queued pong responses are written & flushed into the underlying stream.
pub fn close(&mut self, code: Option<CloseFrame>) -> Result<(), ProtocolError>
pub fn close(&mut self, code: Option<CloseFrame>) -> Result<(), ProtocolError>
Close the connection.
This function guarantees that the close frame will be queued.
There is no need to call it again. Calling this function is
the same as calling write(Message::Close(..)).
After queuing the close frame you should continue calling read or
flush to drive the close handshake to completion.
The websocket RFC defines that the underlying connection should be closed by the server. This crate takes care of this asymmetry for you.
When the close handshake is finished (we have both sent and received
a close message), read or flush will return
ProtocolError::Io (close) if this endpoint is the server.
If this endpoint is a client, ProtocolError::Io (close) will only be
returned after the server has closed the underlying connection.
It is thus safe to drop the underlying connection as soon as ProtocolError::Io (close)
is returned from read or flush.
Trait Implementations§
§impl Debug for BlockingClientWebSocket
impl Debug for BlockingClientWebSocket
§impl Deref for BlockingClientWebSocket
impl Deref for BlockingClientWebSocket
§impl DerefMut for BlockingClientWebSocket
impl DerefMut for BlockingClientWebSocket
§fn deref_mut(&mut self) -> &mut <BlockingClientWebSocket as Deref>::Target
fn deref_mut(&mut self) -> &mut <BlockingClientWebSocket as Deref>::Target
Auto Trait Implementations§
impl !Freeze for BlockingClientWebSocket
impl !RefUnwindSafe for BlockingClientWebSocket
impl !Sync for BlockingClientWebSocket
impl !UnwindSafe for BlockingClientWebSocket
impl Send for BlockingClientWebSocket
impl Unpin for BlockingClientWebSocket
impl UnsafeUnpin for BlockingClientWebSocket
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more