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 async fn connect<P>(path: P) -> Result<UnixStream, Error>
pub async fn connect<P>(path: P) -> Result<UnixStream, Error>
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.
Sourcepub fn from_std(stream: UnixStream) -> Result<UnixStream, Error>
pub fn from_std(stream: UnixStream) -> Result<UnixStream, Error>
Consumes a UnixStream in the standard library and returns a
nonblocking UnixStream from this crate.
The returned stream will be associated with the given event loop
specified by handle and is ready to perform I/O.
§Panics
This function panics if thread-local runtime is not set.
The runtime is usually set implicitly when this function is called
from a future driven by a tokio runtime, otherwise runtime can be set
explicitly with Handle::enter function.
Sourcepub fn pair() -> Result<(UnixStream, UnixStream), Error>
pub fn pair() -> Result<(UnixStream, UnixStream), Error>
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 default event loop’s handle.
Sourcepub fn local_addr(&self) -> Result<SocketAddr, Error>
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Returns the socket address of the local half of this connection.
Sourcepub fn peer_addr(&self) -> Result<SocketAddr, Error>
pub fn peer_addr(&self) -> Result<SocketAddr, Error>
Returns the socket address of the remote half of this connection.
Sourcepub fn peer_cred(&self) -> Result<UCred, Error>
pub fn peer_cred(&self) -> Result<UCred, Error>
Returns effective credentials of the process which called connect or pair.
Sourcepub fn take_error(&self) -> Result<Option<Error>, Error>
pub fn take_error(&self) -> Result<Option<Error>, Error>
Returns the value of the SO_ERROR option.
Sourcepub fn shutdown(&self, how: Shutdown) -> Result<(), Error>
pub fn shutdown(&self, how: Shutdown) -> Result<(), Error>
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).
Sourcepub fn split<'a>(&'a mut self) -> (ReadHalf<'a>, WriteHalf<'a>)
pub fn split<'a>(&'a mut self) -> (ReadHalf<'a>, WriteHalf<'a>)
Split a UnixStream into a read half and a write half, which can be used
to read and write the stream concurrently.
This method is more efficient than into_split, but the halves cannot be
moved into independently spawned tasks.
Sourcepub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)
pub fn into_split(self) -> (OwnedReadHalf, OwnedWriteHalf)
Splits a UnixStream into a read half and a write half, which can be used
to read and write the stream concurrently.
Unlike split, the owned halves can be moved to separate tasks, however
this comes at the cost of a heap allocation.
Note: Dropping the write half will shut down the write half of the
stream. This is equivalent to calling shutdown(Write) on the UnixStream.
Trait Implementations§
Source§impl AsRawFd for UnixStream
impl AsRawFd for UnixStream
Source§impl AsyncRead for UnixStream
impl AsyncRead for UnixStream
Source§unsafe fn prepare_uninitialized_buffer(&self, _: &mut [MaybeUninit<u8>]) -> bool
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [MaybeUninit<u8>]) -> bool
read. Returns
true if the supplied buffer was zeroed out. Read moreSource§impl AsyncWrite for UnixStream
impl AsyncWrite for UnixStream
Source§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 moreSource§fn poll_flush(
self: Pin<&mut UnixStream>,
_: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut UnixStream>, _: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Source§impl Debug for UnixStream
impl Debug for UnixStream
Source§impl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
Source§fn try_from(stream: UnixStream) -> Result<UnixStream, Error>
fn try_from(stream: UnixStream) -> Result<UnixStream, Error>
Consumes stream, returning the tokio I/O object.
This is equivalent to
UnixStream::from_std(stream).