Skip to main content

UnixStream

Struct 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§

Source§

impl UnixStream

Source

pub async fn connect<P>(path: P) -> Result<UnixStream, Error>
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.

Source

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.

Source

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.

Source

pub fn local_addr(&self) -> Result<SocketAddr, Error>

Returns the socket address of the local half of this connection.

Source

pub fn peer_addr(&self) -> Result<SocketAddr, Error>

Returns the socket address of the remote half of this connection.

Source

pub fn peer_cred(&self) -> Result<UCred, Error>

Returns effective credentials of the process which called connect or pair.

Source

pub fn take_error(&self) -> Result<Option<Error>, Error>

Returns the value of the SO_ERROR option.

Source

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).

Source

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.

Source

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

Source§

fn as_raw_fd(&self) -> i32

Extracts the raw file descriptor. Read more
Source§

impl AsyncRead for UnixStream

Source§

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
Source§

fn poll_read( self: Pin<&mut UnixStream>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize, Error>>

Attempts to read from the AsyncRead into buf. Read more
Source§

fn poll_read_buf<B>( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B, ) -> Poll<Result<usize, Error>>
where B: BufMut, Self: Sized,

Pulls some bytes from this source into the specified BufMut, returning how many bytes were read. Read more
Source§

impl AsyncWrite for UnixStream

Source§

fn poll_write( self: Pin<&mut UnixStream>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_flush( self: Pin<&mut UnixStream>, _: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_shutdown( self: Pin<&mut UnixStream>, _: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Source§

fn poll_write_buf<B>( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B, ) -> Poll<Result<usize, Error>>
where B: Buf, Self: Sized,

Writes a Buf into this value, returning how many bytes were written. Read more
Source§

impl Debug for UnixStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl TryFrom<UnixStream> for UnixStream

Source§

fn try_from(stream: UnixStream) -> Result<UnixStream, Error>

Consumes stream, returning the tokio I/O object.

This is equivalent to UnixStream::from_std(stream).

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.