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§
source§impl 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§
source§impl AsFd for UnixStream
impl AsFd for UnixStream
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl AsRawFd for UnixStream
impl AsRawFd for UnixStream
source§impl AsyncRead for UnixStream
impl AsyncRead for UnixStream
source§impl AsyncWrite for UnixStream
impl AsyncWrite for UnixStream
source§fn 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>>
buf
into the object. Read moresource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
source§impl Clone for UnixStream
impl Clone for UnixStream
source§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 moresource§impl Debug for UnixStream
impl Debug for UnixStream
source§impl From<Async<UnixStream>> for UnixStream
impl From<Async<UnixStream>> for UnixStream
source§fn from(stream: Async<UnixStream>) -> UnixStream
fn from(stream: Async<UnixStream>) -> UnixStream
source§impl From<UnixStream> for Arc<Async<UnixStream>>
impl From<UnixStream> for Arc<Async<UnixStream>>
source§fn from(val: UnixStream) -> Self
fn from(val: UnixStream) -> Self
source§impl TryFrom<OwnedFd> for UnixStream
impl TryFrom<OwnedFd> for UnixStream
source§impl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
source§fn try_from(stream: UnixStream) -> Result<UnixStream>
fn try_from(stream: UnixStream) -> Result<UnixStream>
impl RefUnwindSafe for UnixStream
impl UnwindSafe for UnixStream
Auto Trait Implementations§
Blanket Implementations§
§impl<T> AsSource for Twhere
T: AsFd,
impl<T> AsSource for Twhere T: AsFd,
§fn source(&self) -> BorrowedFd<'_>
fn source(&self) -> BorrowedFd<'_>
source§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere R: AsyncRead + ?Sized,
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 more