Struct tokio::net::UnixStream
source · [−]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
sourceimpl UnixStream
impl UnixStream
sourcepub async fn connect<P>(path: P) -> Result<UnixStream> where
P: AsRef<Path>,
pub async fn connect<P>(path: P) -> Result<UnixStream> where
P: AsRef<Path>,
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>
pub fn from_std(stream: UnixStream) -> Result<UnixStream>
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)>
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 default event loop’s handle.
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.
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.
sourcepub fn peer_cred(&self) -> Result<UCred>
pub fn peer_cred(&self) -> Result<UCred>
Returns effective credentials of the process which called connect
or pair
.
sourcepub fn take_error(&self) -> Result<Option<Error>>
pub fn take_error(&self) -> Result<Option<Error>>
Returns the value of the SO_ERROR
option.
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
).
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
sourceimpl AsRawFd for UnixStream
impl AsRawFd for UnixStream
sourceimpl AsRef<UnixStream> for ReadHalf<'_>
impl AsRef<UnixStream> for ReadHalf<'_>
sourcefn as_ref(&self) -> &UnixStream
fn as_ref(&self) -> &UnixStream
Performs the conversion.
sourceimpl AsRef<UnixStream> for WriteHalf<'_>
impl AsRef<UnixStream> for WriteHalf<'_>
sourcefn as_ref(&self) -> &UnixStream
fn as_ref(&self) -> &UnixStream
Performs the conversion.
sourceimpl AsRef<UnixStream> for OwnedReadHalf
impl AsRef<UnixStream> for OwnedReadHalf
sourcefn as_ref(&self) -> &UnixStream
fn as_ref(&self) -> &UnixStream
Performs the conversion.
sourceimpl AsRef<UnixStream> for OwnedWriteHalf
impl AsRef<UnixStream> for OwnedWriteHalf
sourcefn as_ref(&self) -> &UnixStream
fn as_ref(&self) -> &UnixStream
Performs the conversion.
sourceimpl AsyncRead for UnixStream
impl AsyncRead for UnixStream
sourceunsafe fn prepare_uninitialized_buffer(&self, _: &mut [MaybeUninit<u8>]) -> bool
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [MaybeUninit<u8>]) -> bool
Prepares an uninitialized buffer to be safe to pass to read
. Returns
true
if the supplied buffer was zeroed out. 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>, _: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
sourceimpl Debug for UnixStream
impl Debug for UnixStream
sourceimpl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
sourcefn try_from(value: UnixStream) -> Result<Self, Self::Error>
fn try_from(value: UnixStream) -> Result<Self, Self::Error>
Consumes value, returning the mio I/O object.
See PollEvented::into_inner
for more details about
resource deregistration that happens during the call.
sourceimpl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
sourcefn try_from(stream: UnixStream) -> Result<Self>
fn try_from(stream: UnixStream) -> Result<Self>
Consumes stream, returning the tokio I/O object.
This is equivalent to
UnixStream::from_std(stream)
.
Auto Trait Implementations
impl !RefUnwindSafe for UnixStream
impl Send for UnixStream
impl Sync for UnixStream
impl Unpin for UnixStream
impl !UnwindSafe for UnixStream
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more