karyon_core::async_runtime::net

Struct UnixStream

pub struct UnixStream {
    inner: Arc<Async<UnixStream>>,
    readable: Option<ReadableOwned<UnixStream>>,
    writable: Option<WritableOwned<UnixStream>>,
}
Expand description

A Unix connection.

A UnixStream can be created by connecting to an endpoint or by accepting an incoming connection.

UnixStream is a bidirectional stream that implements traits AsyncRead and AsyncWrite.

Cloning a UnixStream creates another handle to the same socket. The socket will be closed when all handles to it are dropped. The reading and writing portions of the connection can also be shut down individually with the shutdown() method.

§Examples

use async_net::unix::UnixStream;
use futures_lite::prelude::*;

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

let mut buf = vec![0u8; 1024];
let n = stream.read(&mut buf).await?;

Fields§

§inner: Arc<Async<UnixStream>>§readable: Option<ReadableOwned<UnixStream>>§writable: Option<WritableOwned<UnixStream>>

Implementations§

§

impl UnixStream

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

Creates a Unix connection to given path.

§Examples
use async_net::unix::UnixStream;

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

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

Creates a pair of connected Unix sockets.

§Examples
use async_net::unix::UnixStream;

let (stream1, stream2) = UnixStream::pair()?;

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

Returns the local address this socket is connected to.

§Examples
use async_net::unix::UnixStream;

let stream = UnixStream::connect("/tmp/socket").await?;
println!("Local address is {:?}", stream.local_addr()?);

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

Returns the remote address this socket is connected to.

§Examples
use async_net::unix::UnixStream;

let stream = UnixStream::connect("/tmp/socket").await?;
println!("Connected to {:?}", stream.peer_addr()?);

pub fn shutdown(&self, how: Shutdown) -> Result<(), Error>

Shuts down the read half, write half, or both halves of this connection.

This method will cause all pending and future I/O in the given directions to return immediately with an appropriate value (see the documentation of Shutdown).

use async_net::{Shutdown, unix::UnixStream};

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

Trait Implementations§

§

impl AsFd for UnixStream

§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
§

impl AsRawFd for UnixStream

§

fn as_raw_fd(&self) -> i32

Extracts the raw file descriptor. Read more
§

impl AsyncRead for UnixStream

§

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

Attempt to read from the AsyncRead into buf. Read more
§

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

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

impl AsyncWrite for UnixStream

§

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
§

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

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

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

Attempt to close the object. Read more
§

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

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

impl Clone for UnixStream

§

fn clone(&self) -> UnixStream

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for UnixStream

§

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

Formats the value using the given formatter. Read more
§

impl From<Async<UnixStream>> for UnixStream

§

fn from(stream: Async<UnixStream>) -> UnixStream

Converts to this type from the input type.
§

impl TryFrom<OwnedFd> for UnixStream

§

type Error = Error

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

fn try_from( value: OwnedFd, ) -> Result<UnixStream, <UnixStream as TryFrom<OwnedFd>>::Error>

Performs the conversion.
§

impl TryFrom<UnixStream> for UnixStream

§

type Error = Error

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

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

Performs the conversion.
§

impl RefUnwindSafe for UnixStream

§

impl UnwindSafe for UnixStream

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
§

impl<T> AsSource for T
where T: AsFd,

§

fn source(&self) -> BorrowedFd<'_>

Returns the borrowed file descriptor.
§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

§

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
§

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

Like read(), except it reads into a slice of buffers. Read more
§

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

Reads the entire contents and appends them to a Vec. Read more
§

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

Reads the entire contents and appends them to a String. Read more
§

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
§

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

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

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

Converts this AsyncRead into a [Stream] of bytes. Read more
§

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

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

fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

§

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

Writes some bytes into the byte stream. Read more
§

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

Like write(), except that it writes a slice of buffers. Read more
§

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
§

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

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

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

Closes the writer. Read more
§

fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> EventValueAny for T
where T: Send + Sync + Debug + Any,

Source§

fn value_as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more