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
impl UnixStream
sourcepub fn connect(path: impl AsRef<Path>) -> Result<Self>
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
.
sourcepub fn connect_addr(addr: impl ToSockAddrs) -> Result<Self>
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
.
sourcepub fn try_clone(&self) -> Result<Self>
pub fn try_clone(&self) -> Result<Self>
Creates a new independently owned handle to the underlying socket.
It does not clear the attach state.
sourcepub fn peer_addr(&self) -> Result<SockAddr>
pub fn peer_addr(&self) -> Result<SockAddr>
Returns the socket path of the remote peer of this connection.
sourcepub fn local_addr(&self) -> Result<SockAddr>
pub fn local_addr(&self) -> Result<SockAddr>
Returns the socket path of the local half of this connection.
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 on the specified
portions to return immediately with an appropriate value (see the
documentation of Shutdown
).
sourcepub async fn recv<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
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.
sourcepub async fn recv_exact<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
pub async fn recv_exact<T: IoBufMut>(&self, buffer: T) -> BufResult<usize, T>
Receives exact number of bytes from the socket.
sourcepub async fn recv_vectored<T: IoVectoredBufMut>(
&self,
buffer: T
) -> BufResult<usize, T>
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.
sourcepub async fn send<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
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.
sourcepub async fn send_all<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
pub async fn send_all<T: IoBuf>(&self, buffer: T) -> BufResult<usize, T>
Sends all data to the socket.
sourcepub async fn send_vectored<T: IoVectoredBuf>(
&self,
buffer: T
) -> BufResult<usize, T>
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.