[][src]Struct async_listen::ByteStream

pub struct ByteStream { /* fields omitted */ }

A wrapper around TcpStream and UnixStream

This structure is yielded by the stream created by ListenExt::backpressure_wrapper

This wrapper serves two purposes:

  1. Holds backpressure token
  2. Abstract away differences between TcpStream and UnixStream

The structure implements AsyncRead and AsyncWrite so can be used for protocol implementation directly.

Methods

impl ByteStream[src]

pub fn new_tcp(token: Token, stream: TcpStream) -> ByteStream[src]

Create a bytestream for a tcp socket

pub fn new_unix(token: Token, stream: UnixStream) -> ByteStream[src]

Create a bytestream for a unix socket

pub fn peer_addr(&self) -> Result<PeerAddr>[src]

Returns the remote address that this stream is connected to.

Note: even on non-unix platforms (Windows) PeerAddr still contains Unix option so you don't have to use conditional compilation when matching.

Examples

This example is not tested
let peer = stream.peer_addr()?;
match peer.peer_addr()? {
    PeerAddr::Tcp(addr) => println!("TCP addr {}", addr),
    PeerAddr::Unix(None) => println!("Unnamed unix socket"),
    PeerAddr::Unix(Some(path)) => println!("Unix {}", path.display()),
}

pub fn nodelay(&self) -> Result<bool>[src]

Gets the value of the TCP_NODELAY option on this socket.

For Unix sockets this function always returns true (Unix sockets always behave like the option is off).

For more information about this option, see set_nodelay.

pub fn set_nodelay(&self, nodelay: bool) -> Result<()>[src]

Sets the value of the TCP_NODELAY option on this socket.

If set, this option disables the Nagle algorithm. This means that segments are always sent as soon as possible, even if there is only a small amount of data. When not set, data is buffered until there is a sufficient amount to send out, thereby avoiding the frequent sending of small packets.

For Unix sockets this function does nothing (Unix sockets always behave like the option is enabled, and there is no way to change that).

pub fn shutdown(&self, how: Shutdown) -> Result<(), Error>[src]

Shuts down the read, write, or both halves of this connection.

This function will cause all pending and future I/O calls on the specified portions to immediately return with an appropriate value (see the documentation of Shutdown).

Trait Implementations

impl AsyncRead for ByteStream[src]

impl AsyncWrite for ByteStream[src]

impl Debug for ByteStream[src]

impl From<(Token, TcpStream)> for ByteStream[src]

impl From<(Token, UnixStream)> for ByteStream[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

impl<T> BorrowMut<T> for T where
    T: ?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, 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<T> WriteExt for T where
    T: AsyncWrite + ?Sized
[src]