[][src]Struct ws_stream_tungstenite::WsStream

pub struct WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
{ /* fields omitted */ }

Takes a WebSocketStream and implements futures 0.3 AsyncRead/AsyncWrite/AsyncBufRead.

Errors

Errors returned directly are generally io errors from the underlying stream. Only fatal errors are returned in band, so consider them fatal and drop the WsStream object.

Other errors are returned out of band through pharos:

On reading, eg. AsyncRead::poll_read:

  • WsErr::Protocol: The remote made a websocket protocol violation. The connection will be closed gracefully indicating to the remote what went wrong. You can just keep calling poll_read until None is returned.
  • tungstenite returned a utf8 error. Pharos will return it as a Tungstenite error. This means the remote send a text message, which is not supported, so the connection will be gracefully closed. You can just keep calling poll_read until None is returned.
  • WsErr::ReceivedText: This means the remote send a text message, which is not supported, so the connection will be gracefully closed. You can just keep calling poll_read until None is returned.

On writing, eg. AsyncWrite::* all errors are fatal. Note that if you get io::ErrorKind::InvalidData, it means you send data that exceeds the tungstenite Capacity. Eg. it leads to a message that exceeds the max message size in tungstenite. It's intended that ws_stream_tungstenite protects from this by splitting the data in several messages, but for now there is no way to find out what the max message size is from the underlying WebSocketStream, so that will require changes in the API of tungstenite and async-tungstenite, so that will be for a future release.

When a Protocol error is encountered during writing, it indicates that either ws_stream_tungstenite or tungstenite have a bug so it will panic.

Implementations

impl<S> WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

pub fn new(inner: ATungSocket<S>) -> Self[src]

Create a new WsStream.

Trait Implementations

impl<S> AsyncBufRead for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

impl<S> AsyncRead for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

impl<S> AsyncRead for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

impl<S> AsyncWrite for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

fn poll_write(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>,
    buf: &[u8]
) -> Poll<Result<usize>>
[src]

Will always flush the underlying socket. Will always create an entire Websocket message from every write, so call with a sufficiently large buffer if you have performance problems. Don't call with a buffer larger than the max message size accepted by the remote endpoint.

fn poll_write_vectored(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>,
    bufs: &[IoSlice<'_>]
) -> Poll<Result<usize>>
[src]

Will always flush the underlying socket. Will always create an entire Websocket message from every write, so call with a sufficiently large buffers if you have performance problems. Don't call with a buffer larger than the max message size accepted by the remote endpoint.

impl<S> AsyncWrite for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

fn poll_write(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>,
    buf: &[u8]
) -> Poll<Result<usize>>
[src]

Will always flush the underlying socket. Will always create an entire Websocket message from every write, so call with a sufficiently large buffer if you have performance problems. Don't call with a buffer larger than the max message size accepted by the remote endpoint.

impl<S> Debug for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

impl<S> Observable<WsEvent> for WsStream<S> where
    S: AsyncRead + AsyncWrite + Unpin
[src]

type Error = WsErr

The error type that is returned if observing is not possible. Read more

Auto Trait Implementations

impl<S> !RefUnwindSafe for WsStream<S>

impl<S> Send for WsStream<S> where
    S: Send

impl<S> !Sync for WsStream<S>

impl<S> Unpin for WsStream<S>

impl<S> !UnwindSafe for WsStream<S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<R> AsyncBufReadExt for R where
    R: AsyncBufRead + ?Sized
[src]

impl<R> AsyncBufReadExt for R where
    R: AsyncBufRead + ?Sized

impl<R> AsyncReadExt for R where
    R: AsyncRead + ?Sized
[src]

impl<R> AsyncReadExt for R where
    R: AsyncRead + ?Sized

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?Sized
[src]

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> BufReadExt for T where
    T: AsyncBufRead + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ReadExt for T where
    T: AsyncRead + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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

impl<T> WriteExt for T where
    T: AsyncWrite + ?Sized
[src]