Struct compio_net::UnixStream

source ·
pub struct UnixStream { /* private fields */ }
Expand description

A Unix stream between two local sockets on Windows & WSL.

A Unix stream can either be created by connecting to an endpoint, via the connect method, or by accepting a connection from a listener.

Examples

use compio_net::UnixStream;

compio_runtime::block_on(async {
    // Connect to a peer
    let mut stream = UnixStream::connect("unix-server.sock").unwrap();

    // Write some data.
    stream.send("hello world!").await.unwrap();
})

Implementations§

source§

impl UnixStream

source

pub fn connect(path: impl AsRef<Path>) -> Result<Self>

Opens a Unix connection to the specified file path. There must be a UnixListener or equivalent listening on the corresponding Unix domain socket to successfully connect and return a UnixStream.

source

pub fn connect_addr(addr: impl ToSockAddrs) -> Result<Self>

Opens a Unix connection to the specified address. There must be a UnixListener or equivalent listening on the corresponding Unix domain socket to successfully connect and return a UnixStream.

source

pub fn try_clone(&self) -> Result<Self>

Creates a new independently owned handle to the underlying socket.

It does not clear the attach state.

source

pub fn peer_addr(&self) -> Result<SockAddr>

Returns the socket path of the remote peer of this connection.

source

pub fn local_addr(&self) -> Result<SockAddr>

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

source

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 on the specified portions to return immediately with an appropriate value (see the documentation of Shutdown).

source

pub async fn recv<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>

Receives a packet of data from the socket into the buffer, returning the original buffer and quantity of data received.

source

pub async fn recv_exact<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>

Receives exact number of bytes from the socket.

source

pub async fn recv_vectored<T: IoVectoredBufMut>( &self, buffer: T ) -> BufResult<usize, T>

Receives a packet of data from the socket into the buffer, returning the original buffer and quantity of data received.

source

pub async fn send<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>

Sends some data to the socket from the buffer, returning the original buffer and quantity of data sent.

source

pub async fn send_all<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>

Sends all data to the socket.

source

pub async fn send_vectored<T: IoVectoredBuf>( &self, buffer: T ) -> BufResult<usize, T>

Sends some data to the socket from the buffer, returning the original buffer and quantity of data sent.

Trait Implementations§

source§

impl AsRawFd for UnixStream

source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
source§

impl FromRawFd for UnixStream

source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
source§

impl IntoRawFd for UnixStream

source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

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>,

§

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>,

§

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.