Struct UnixStream

Source
pub struct UnixStream { /* private fields */ }
Available on Unix only.
Expand description

A Unix stream socket.

This type is an async version of std::os::unix::net::UnixStream.

§Examples

use async_std::os::unix::net::UnixStream;
use async_std::prelude::*;

let mut stream = UnixStream::connect("/tmp/socket").await?;
stream.write_all(b"hello world").await?;

let mut response = Vec::new();
stream.read_to_end(&mut response).await?;

Implementations§

Source§

impl UnixStream

Source

pub async fn connect<P: AsRef<Path>>(path: P) -> Result<UnixStream>

Connects to the socket to the specified address.

§Examples
use async_std::os::unix::net::UnixStream;

let stream = UnixStream::connect("/tmp/socket").await?;
Source

pub fn pair() -> Result<(UnixStream, UnixStream)>

Creates an unnamed pair of connected sockets.

Returns two streams which are connected to each other.

§Examples
use async_std::os::unix::net::UnixStream;

let stream = UnixStream::pair()?;
Source

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

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

§Examples
use async_std::os::unix::net::UnixStream;

let stream = UnixStream::connect("/tmp/socket").await?;
let addr = stream.local_addr()?;
Source

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

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

§Examples
use async_std::os::unix::net::UnixStream;

let stream = UnixStream::connect("/tmp/socket").await?;
let peer = stream.peer_addr()?;
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 calls on the specified portions to immediately return with an appropriate value (see the documentation of Shutdown).

use async_std::os::unix::net::UnixStream;
use std::net::Shutdown;

let stream = UnixStream::connect("/tmp/socket").await?;
stream.shutdown(Shutdown::Both)?;

Trait Implementations§

Source§

impl AsRawFd for UnixStream

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for UnixStream

Source§

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

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

impl From<UnixStream> for UnixStream

Source§

fn from(stream: UnixStream) -> UnixStream

Converts a std::os::unix::net::UnixStream into its asynchronous equivalent.

Source§

impl FromRawFd for UnixStream

Source§

unsafe fn from_raw_fd(fd: RawFd) -> UnixStream

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

impl Read for &UnixStream

Source§

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

Attempt to read from the AsyncRead into buf.
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into bufs using vectored IO operations.
Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ImplFuture<Result<usize>>
where Self: Unpin,

Reads some bytes from the byte stream. Read more
Source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Like read, except that it reads into a slice of buffers. Read more
Source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Reads all bytes from the byte stream. Read more
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Reads all bytes from the byte stream and appends them into a string. Read more
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ImplFuture<Result<()>>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adaptor which will read at most limit bytes from it. Read more
Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to a Stream over its bytes. Read more
Source§

fn chain<R: Read>(self, next: R) -> Chain<Self, R>
where Self: Sized,

Creates an adaptor which will chain this stream with another. Read more
Source§

impl Read for UnixStream

Source§

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

Attempt to read from the AsyncRead into buf.
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into bufs using vectored IO operations.
Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ImplFuture<Result<usize>>
where Self: Unpin,

Reads some bytes from the byte stream. Read more
Source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Like read, except that it reads into a slice of buffers. Read more
Source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Reads all bytes from the byte stream. Read more
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Reads all bytes from the byte stream and appends them into a string. Read more
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ImplFuture<Result<()>>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adaptor which will read at most limit bytes from it. Read more
Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to a Stream over its bytes. Read more
Source§

fn chain<R: Read>(self, next: R) -> Chain<Self, R>
where Self: Sized,

Creates an adaptor which will chain this stream with another. Read more
Source§

impl Write for &UnixStream

Source§

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

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

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

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

fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object.
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations.
Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> ImplFuture<Result<usize>>
where Self: Unpin,

Writes some bytes into the byte stream. Read more
Source§

fn flush(&mut self) -> ImplFuture<Result<()>>
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
Source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Like write, except that it writes from a slice of buffers. Read more
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> ImplFuture<Result<()>>
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
Source§

fn write_fmt<'a>(&'a mut self, fmt: Arguments<'_>) -> ImplFuture<Result<()>>
where Self: Unpin,

Writes a formatted string into this writer, returning any error encountered. Read more
Source§

impl Write for UnixStream

Source§

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

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

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

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

fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Attempt to close the object.
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize>>

Attempt to write bytes from bufs into the object using vectored IO operations.
Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> ImplFuture<Result<usize>>
where Self: Unpin,

Writes some bytes into the byte stream. Read more
Source§

fn flush(&mut self) -> ImplFuture<Result<()>>
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
Source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> ImplFuture<Result<usize>>
where Self: Unpin,

Like write, except that it writes from a slice of buffers. Read more
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> ImplFuture<Result<()>>
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
Source§

fn write_fmt<'a>(&'a mut self, fmt: Arguments<'_>) -> ImplFuture<Result<()>>
where Self: Unpin,

Writes a formatted string into this writer, returning any error encountered. 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> ReadExt for T
where T: Read + ?Sized,

Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>
where Self: Unpin,

Reads some bytes from the byte stream. Read more
Source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], ) -> ReadVectoredFuture<'a, Self>
where Self: Unpin,

Like read, except that it reads into a slice of buffers. Read more
Source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8>, ) -> ReadToEndFuture<'a, Self>
where Self: Unpin,

Reads all bytes from the byte stream. Read more
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ReadToStringFuture<'a, Self>
where Self: Unpin,

Reads all bytes from the byte stream and appends them into a string. Read more
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adaptor which will read at most limit bytes from it. Read more
Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to a Stream over its bytes. Read more
Source§

fn chain<R: Read>(self, next: R) -> Chain<Self, R>
where Self: Sized,

Creates an adaptor which will chain this stream with another. Read more
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.
Source§

impl<T> WriteExt for T
where T: Write + ?Sized,

Source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>
where Self: Unpin,

Writes some bytes into the byte stream. Read more
Source§

fn flush(&mut self) -> FlushFuture<'_, Self>
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
Source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> WriteVectoredFuture<'a, Self>
where Self: Unpin,

Like write, except that it writes from a slice of buffers. Read more
Source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
Source§

fn write_fmt<'a>(&'a mut self, fmt: Arguments<'_>) -> WriteFmtFuture<'a, Self>
where Self: Unpin,

Writes a formatted string into this writer, returning any error encountered. Read more