Struct UnixStream
pub struct UnixStream {
inner: Arc<Async<UnixStream>>,
readable: Option<ReadableOwned<UnixStream>>,
writable: Option<WritableOwned<UnixStream>>,
}
Expand description
A Unix connection.
A UnixStream
can be created by connect
ing to an endpoint or by
accept
ing an incoming connection.
UnixStream
is a bidirectional stream that implements traits AsyncRead
and
AsyncWrite
.
Cloning a UnixStream
creates another handle to the same socket. The socket will be closed
when all handles to it are dropped. The reading and writing portions of the connection can also
be shut down individually with the shutdown()
method.
§Examples
use async_net::unix::UnixStream;
use futures_lite::prelude::*;
let mut stream = UnixStream::connect("/tmp/socket").await?;
stream.write_all(b"hello").await?;
let mut buf = vec![0u8; 1024];
let n = stream.read(&mut buf).await?;
Fields§
§inner: Arc<Async<UnixStream>>
§readable: Option<ReadableOwned<UnixStream>>
§writable: Option<WritableOwned<UnixStream>>
Implementations§
§impl UnixStream
impl UnixStream
pub async fn connect<P>(path: P) -> Result<UnixStream, Error>
pub async fn connect<P>(path: P) -> Result<UnixStream, Error>
Creates a Unix connection to given path.
§Examples
use async_net::unix::UnixStream;
let stream = UnixStream::connect("/tmp/socket").await?;
pub fn pair() -> Result<(UnixStream, UnixStream), Error>
pub fn pair() -> Result<(UnixStream, UnixStream), Error>
Creates a pair of connected Unix sockets.
§Examples
use async_net::unix::UnixStream;
let (stream1, stream2) = UnixStream::pair()?;
pub fn local_addr(&self) -> Result<SocketAddr, Error>
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Returns the local address this socket is connected to.
§Examples
use async_net::unix::UnixStream;
let stream = UnixStream::connect("/tmp/socket").await?;
println!("Local address is {:?}", stream.local_addr()?);
pub fn peer_addr(&self) -> Result<SocketAddr, Error>
pub fn peer_addr(&self) -> Result<SocketAddr, Error>
Returns the remote address this socket is connected to.
§Examples
use async_net::unix::UnixStream;
let stream = UnixStream::connect("/tmp/socket").await?;
println!("Connected to {:?}", stream.peer_addr()?);
pub fn shutdown(&self, how: Shutdown) -> Result<(), Error>
pub fn shutdown(&self, how: Shutdown) -> Result<(), Error>
Shuts down the read half, write half, or both halves of this connection.
This method will cause all pending and future I/O in the given directions to return
immediately with an appropriate value (see the documentation of Shutdown
).
use async_net::{Shutdown, unix::UnixStream};
let stream = UnixStream::connect("/tmp/socket").await?;
stream.shutdown(Shutdown::Both)?;
Trait Implementations§
§impl AsFd for UnixStream
impl AsFd for UnixStream
§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
§impl AsyncRead for UnixStream
impl AsyncRead for UnixStream
§impl AsyncWrite for UnixStream
impl AsyncWrite for UnixStream
§fn poll_write(
self: Pin<&mut UnixStream>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut UnixStream>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
buf
into the object. Read more§fn poll_flush(
self: Pin<&mut UnixStream>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut UnixStream>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>
§fn poll_close(
self: Pin<&mut UnixStream>,
_: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_close( self: Pin<&mut UnixStream>, _: &mut Context<'_>, ) -> Poll<Result<(), Error>>
§impl Clone for UnixStream
impl Clone for UnixStream
§fn clone(&self) -> UnixStream
fn clone(&self) -> UnixStream
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for UnixStream
impl Debug for UnixStream
§impl From<Async<UnixStream>> for UnixStream
impl From<Async<UnixStream>> for UnixStream
§fn from(stream: Async<UnixStream>) -> UnixStream
fn from(stream: Async<UnixStream>) -> UnixStream
§impl TryFrom<OwnedFd> for UnixStream
impl TryFrom<OwnedFd> for UnixStream
§impl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
§fn try_from(stream: UnixStream) -> Result<UnixStream, Error>
fn try_from(stream: UnixStream) -> Result<UnixStream, Error>
impl RefUnwindSafe for UnixStream
impl UnwindSafe for UnixStream
Auto Trait Implementations§
impl Freeze for UnixStream
impl Send for UnixStream
impl Sync for UnixStream
impl Unpin for UnixStream
Blanket Implementations§
§impl<T> AsSource for Twhere
T: AsFd,
impl<T> AsSource for Twhere
T: AsFd,
§fn source(&self) -> BorrowedFd<'_>
fn source(&self) -> BorrowedFd<'_>
§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
§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,
§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,
§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,
§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,
§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 more§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 more§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
§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,
§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,
§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,
§fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>where
Self: Unpin,
§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 more