pub struct ByteStream { /* private fields */ }
Expand description
A wrapper around TcpStream and UnixStream
This structure is yielded by the stream created by
ListenExt::backpressure_wrapper
This wrapper serves two purposes:
- Holds backpressure token
- Abstract away differences between TcpStream and UnixStream
The structure implements AsyncRead and AsyncWrite so can be used for protocol implementation directly.
§Notes on Cloning
Cloning a ByteStream
is a shallow clone, both resulting ByteStream
structures hold the same backpressure token (and the same underlying OS socket).
The backpressure slot will be freed (which means new connection can be accepted)
when the last clone of ByteStream
is dropped.
Implementations§
Source§impl ByteStream
impl ByteStream
Sourcepub fn new_tcp(token: Token, stream: TcpStream) -> ByteStream
pub fn new_tcp(token: Token, stream: TcpStream) -> ByteStream
Create a bytestream for a tcp socket
Sourcepub fn new_tcp_detached(stream: TcpStream) -> ByteStream
pub fn new_tcp_detached(stream: TcpStream) -> ByteStream
Create a bytestream for a tcp socket (without token)
This can be used with interfaces that require a ByteStream
but
aren’t got from the listener that have backpressure applied. For
example, if you have two listeners in the single app or even for
client connections.
Sourcepub fn new_unix(token: Token, stream: UnixStream) -> ByteStream
pub fn new_unix(token: Token, stream: UnixStream) -> ByteStream
Create a bytestream for a unix socket
Sourcepub fn new_unix_detached(stream: UnixStream) -> ByteStream
pub fn new_unix_detached(stream: UnixStream) -> ByteStream
Create a bytestream for a unix socket (without token)
This can be used with interfaces that require a ByteStream
but
aren’t got from the listener that have backpressure applied. For
example, if you have two listeners in the single app or even for
client connections.
Sourcepub fn peer_addr(&self) -> Result<PeerAddr>
pub fn peer_addr(&self) -> Result<PeerAddr>
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
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()),
}
Sourcepub fn nodelay(&self) -> Result<bool>
pub fn nodelay(&self) -> Result<bool>
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
.
Sourcepub fn set_nodelay(&self, nodelay: bool) -> Result<()>
pub fn set_nodelay(&self, nodelay: bool) -> Result<()>
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).
Trait Implementations§
Source§impl Clone for ByteStream
impl Clone for ByteStream
Source§fn clone(&self) -> ByteStream
fn clone(&self) -> ByteStream
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ByteStream
impl Debug for ByteStream
Source§impl From<(Token, UnixStream)> for ByteStream
impl From<(Token, UnixStream)> for ByteStream
Source§fn from((token, stream): (Token, UnixStream)) -> ByteStream
fn from((token, stream): (Token, UnixStream)) -> ByteStream
Source§impl AsyncRead for &ByteStream
impl AsyncRead for &ByteStream
Source§impl AsyncRead for ByteStream
impl AsyncRead for ByteStream
Source§impl AsyncWrite for &ByteStream
impl AsyncWrite for &ByteStream
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf
into the object. Read moreSource§fn poll_flush(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Source§impl AsyncWrite for ByteStream
impl AsyncWrite for ByteStream
Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf
into the object. Read moreSource§fn poll_flush(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Auto Trait Implementations§
impl Freeze for ByteStream
impl RefUnwindSafe for ByteStream
impl Send for ByteStream
impl Sync for ByteStream
impl Unpin for ByteStream
impl UnwindSafe for ByteStream
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
Source§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
Source§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
Source§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
buf
. Read moreSource§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read moreSource§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
Source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>where
Self: Unpin,
Source§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectoredFuture<'a, Self>where
Self: Unpin,
Source§fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>where
Self: Unpin,
Source§fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
Source§fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
dyn AsyncWrite + Send + 'a
. Read moreSource§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ReadExt for T
impl<T> ReadExt for T
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
Source§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
Source§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
Source§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
buf
. Read moreSource§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read moreSource§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more