Trait UnixSocketInterface

Source
pub trait UnixSocketInterface {
    type UnixStream;
    type UnixListener;
    type SocketAddr;

    // Required methods
    fn unix_stream_connect<'async_trait>(
        socket_path: impl 'async_trait + AsRef<Path>,
    ) -> Pin<Box<dyn Future<Output = IoResult<Self::UnixStream>> + 'async_trait>>
       where Self: 'async_trait;
    fn unix_stream_shutdown<'life0, 'async_trait>(
        s: &'life0 mut Self::UnixStream,
    ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn unix_stream_write<'life0, 'life1, 'async_trait>(
        s: &'life0 mut Self::UnixStream,
        buf: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = IoResult<usize>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn unix_stream_write_all<'life0, 'life1, 'async_trait>(
        s: &'life0 mut Self::UnixStream,
        buf: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn unix_stream_read<'life0, 'life1, 'async_trait>(
        s: &'life0 mut Self::UnixStream,
        buf: &'life1 mut [u8],
    ) -> Pin<Box<dyn Future<Output = IoResult<usize>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn unix_stream_read_exact<'life0, 'life1, 'async_trait>(
        s: &'life0 mut Self::UnixStream,
        buf: &'life1 mut [u8],
    ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn unix_listener_bind<'async_trait>(
        path: impl 'async_trait + AsRef<Path>,
    ) -> Pin<Box<dyn Future<Output = IoResult<Self::UnixListener>> + 'async_trait>>
       where Self: 'async_trait;
    fn unix_listener_accept<'life0, 'async_trait>(
        s: &'life0 mut Self::UnixListener,
    ) -> Pin<Box<dyn Future<Output = IoResult<(Self::UnixStream, Self::SocketAddr)>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Provide a unified interface to unix sockets in various points of existence. You can provide your own version of this in future if you have a runtime that is not supported.

Note that this is very unideal… In future, I am likely to do a couple things:

  • Move the common interface out into a crate
  • Make the trait delegate to poll functions and add a crapton of Future structs for the various functions, to avoid the allocations involved in async_trait. Maybe even see if I can’t make a macro for that.

Required Associated Types§

Source

type UnixStream

Unix stream type - equivalent to std::os::unix::net::UnixStream

Source

type UnixListener

Unix listener type - equivalent to std::os::unix::net::UnixListener

Source

type SocketAddr

Unix socket address type - equivalent to std::os::unix::net::SocketAddr

Required Methods§

Source

fn unix_stream_connect<'async_trait>( socket_path: impl 'async_trait + AsRef<Path>, ) -> Pin<Box<dyn Future<Output = IoResult<Self::UnixStream>> + 'async_trait>>
where Self: 'async_trait,

Attempt to connect to a stream. Analogous to std::os::unix::net::UnixStream::connect

Source

fn unix_stream_shutdown<'life0, 'async_trait>( s: &'life0 mut Self::UnixStream, ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempt to shutdown a stream. Because shutting down read vs write directions is not available in all runtimes - looks @ tokio - it is necessary for this to be kind of barebones.

This will do as much shutdown as it is possible to do with the API.

Source

fn unix_stream_write<'life0, 'life1, 'async_trait>( s: &'life0 mut Self::UnixStream, buf: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = IoResult<usize>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Write a u8 slice to the unix stream, returning the # of actual bytes written.

Ok(0) means it prob cant take anymore.

Source

fn unix_stream_write_all<'life0, 'life1, 'async_trait>( s: &'life0 mut Self::UnixStream, buf: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Write a u8 slice to the unix stream, repeating until it actually works all the way.

Source

fn unix_stream_read<'life0, 'life1, 'async_trait>( s: &'life0 mut Self::UnixStream, buf: &'life1 mut [u8], ) -> Pin<Box<dyn Future<Output = IoResult<usize>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a u8 slice into the buffer, returning the # of actual bytes read

Ok(0) means it prob cant take anymore out of the stream for now

Source

fn unix_stream_read_exact<'life0, 'life1, 'async_trait>( s: &'life0 mut Self::UnixStream, buf: &'life1 mut [u8], ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a u8 slice from the unix stream, repeating until it reads everything.

Source

fn unix_listener_bind<'async_trait>( path: impl 'async_trait + AsRef<Path>, ) -> Pin<Box<dyn Future<Output = IoResult<Self::UnixListener>> + 'async_trait>>
where Self: 'async_trait,

Bind as a unix listening socket at the path

Source

fn unix_listener_accept<'life0, 'async_trait>( s: &'life0 mut Self::UnixListener, ) -> Pin<Box<dyn Future<Output = IoResult<(Self::UnixStream, Self::SocketAddr)>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Accept one new connection

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§