pub struct UnixStream { /* private fields */ }
Expand description
A structure representing a connected Unix socket.
This socket can be connected directly with UnixStream::connect
or accepted
from a listener with UnixListener::incoming
. Additionally, a pair of
anonymous Unix sockets can be created with UnixStream::pair
.
Implementations§
Source§impl UnixStream
impl UnixStream
Sourcepub fn connect(path: impl AsRef<Path>) -> ConnectFuture ⓘ
pub fn connect(path: impl AsRef<Path>) -> ConnectFuture ⓘ
Connects to the socket named by path
.
This function will create a new Unix socket and connect to the path specified, associating the returned stream with the default event loop’s handle.
§Examples
use futures_net::UnixStream;
let stream = UnixStream::connect("/tmp/sock").await;
Sourcepub fn pair() -> Result<(UnixStream, UnixStream)>
pub fn pair() -> Result<(UnixStream, UnixStream)>
Creates an unnamed pair of connected sockets.
This function will create a pair of interconnected Unix sockets for communicating back and forth between one another. Each socket will be associated with the event loop whose handle is also provided.
§Examples
use futures_net::UnixStream;
let (sock1, sock2) = UnixStream::pair()?;
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the socket address of the local half of this connection.
§Examples
use futures_net::UnixStream;
let stream = UnixStream::connect("/tmp/sock").await?;
let addr = stream.local_addr()?;
Sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the socket address of the remote half of this connection.
§Examples
use futures_net::UnixStream;
let stream = UnixStream::connect("/tmp/sock").await?;
let addr = stream.peer_addr()?;
Sourcepub fn peer_cred(&self) -> Result<UCred>
pub fn peer_cred(&self) -> Result<UCred>
Returns effective credentials of the process which called connect
or socketpair
.
§Examples
use futures_net::UnixStream;
let stream = UnixStream::connect("/tmp/sock").await?;
let cred = stream.peer_cred()?;
Sourcepub fn shutdown(&self, how: Shutdown) -> Result<()>
pub fn shutdown(&self, how: Shutdown) -> Result<()>
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
).
use futures_net::UnixStream;
use std::net::Shutdown;
let stream = UnixStream::connect("/tmp/sock").await?;
stream.shutdown(Shutdown::Both)?;
Trait Implementations§
Source§impl AsRawFd for UnixStream
impl AsRawFd for UnixStream
Source§impl AsyncRead for UnixStream
impl AsyncRead for UnixStream
Source§impl AsyncReadReady for UnixStream
impl AsyncReadReady 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 AsyncWriteReady for UnixStream
impl AsyncWriteReady for UnixStream
Source§impl Debug for UnixStream
impl Debug for UnixStream
Source§impl TakeError for UnixStream
impl TakeError for UnixStream
Source§fn take_error(&self) -> Result<Option<Self::Ok>, Self::Err>
fn take_error(&self) -> Result<Option<Self::Ok>, Self::Err>
Returns the value of the SO_ERROR
option.
§Examples
use futures_net::UnixStream;
use async_ready::TakeError;
let stream = UnixStream::connect("/tmp/sock").await?;
if let Ok(Some(err)) = stream.take_error() {
println!("Got error: {:?}", err);
}
impl Unpin for UnixStream
Auto Trait Implementations§
impl !Freeze for UnixStream
impl !RefUnwindSafe for UnixStream
impl Send for UnixStream
impl Sync for UnixStream
impl !UnwindSafe for UnixStream
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
buf
in asynchronous
manner, returning a future type. Read moreSource§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
AsyncRead
into bufs
using vectored
IO operations. Read moreSource§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf
,
returning an error if end of file (EOF) is hit sooner. Read moreSource§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
AsyncRead
. Read moreSource§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
AsyncRead
. Read moreSource§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
Source§fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
AsyncWrite
. Read moreSource§fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
AsyncWrite
.Source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
buf
into the object. Read moreSource§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
bufs
into the object using vectored
IO operations. Read more