Struct async_net::unix::UnixStream
source · [−]pub struct UnixStream { /* private fields */ }
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?;
Implementations
sourceimpl UnixStream
impl UnixStream
sourcepub async fn connect<P: AsRef<Path>>(path: P) -> Result<UnixStream>
pub async fn connect<P: AsRef<Path>>(path: P) -> Result<UnixStream>
Creates a Unix connection to given path.
Examples
use async_net::unix::UnixStream;
let stream = UnixStream::connect("/tmp/socket").await?;
sourcepub fn pair() -> Result<(UnixStream, UnixStream)>
pub fn pair() -> Result<(UnixStream, UnixStream)>
Creates a pair of connected Unix sockets.
Examples
use async_net::unix::UnixStream;
let (stream1, stream2) = UnixStream::pair()?;
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
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()?);
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
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()?);
sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
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
sourceimpl AsFd for UnixStream
impl AsFd for UnixStream
sourcefn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Borrows the file descriptor. Read more
sourceimpl AsRawFd for UnixStream
impl AsRawFd for UnixStream
sourceimpl AsyncRead for UnixStream
impl AsyncRead for UnixStream
sourcefn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize>>
Attempt to read from the AsyncRead
into buf
. Read more
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
Attempt to read from the AsyncRead
into bufs
using vectored
IO operations. Read more
sourceimpl AsyncWrite for UnixStream
impl AsyncWrite for UnixStream
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
sourceimpl Clone for UnixStream
impl Clone for UnixStream
sourcefn clone(&self) -> UnixStream
fn clone(&self) -> UnixStream
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for UnixStream
impl Debug for UnixStream
sourceimpl From<Async<UnixStream>> for UnixStream
impl From<Async<UnixStream>> for UnixStream
sourcefn from(stream: Async<UnixStream>) -> UnixStream
fn from(stream: Async<UnixStream>) -> UnixStream
Converts to this type from the input type.
sourceimpl From<UnixStream> for Arc<Async<UnixStream>>
impl From<UnixStream> for Arc<Async<UnixStream>>
sourcefn from(val: UnixStream) -> Self
fn from(val: UnixStream) -> Self
Converts to this type from the input type.
sourceimpl TryFrom<OwnedFd> for UnixStream
impl TryFrom<OwnedFd> for UnixStream
sourceimpl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
sourcefn try_from(stream: UnixStream) -> Result<UnixStream>
fn try_from(stream: UnixStream) -> Result<UnixStream>
Performs the conversion.
impl RefUnwindSafe for UnixStream
impl UnwindSafe for UnixStream
Auto Trait Implementations
Blanket Implementations
sourceimpl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
sourcefn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
Reads some bytes from the byte stream. Read more
sourcefn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
sourcefn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
sourcefn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
sourcefn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
Reads the exact number of bytes required to fill buf
. Read more
sourcefn take(self, limit: u64) -> Take<Self>
fn take(self, limit: u64) -> Take<Self>
Creates an adapter which will read at most limit
bytes from it. Read more
sourceimpl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
sourcefn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> where
Self: Unpin,
Writes some bytes into the byte stream. Read more
sourcefn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self> where
Self: Unpin,
sourcefn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> where
Self: Unpin,
Writes an entire buffer into the byte stream. Read more
sourcefn flush(&mut self) -> FlushFuture<'_, Self> where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self> where
Self: Unpin,
Flushes the stream to ensure that all buffered contents reach their destination. Read more
sourcefn close(&mut self) -> CloseFuture<'_, Self> where
Self: Unpin,
fn close(&mut self) -> CloseFuture<'_, Self> where
Self: Unpin,
Closes the writer. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more