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

    fn unix_stream_connect<'async_trait>(
        socket_path: impl 'async_trait + AsRef<Path>
    ) -> Pin<Box<dyn Future<Output = IoResult<Self::UnixStream>> + 'async_trait>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        Self: 'async_trait
; fn unix_stream_shutdown<'life0, 'async_trait>(
        s: &'life0 mut Self::UnixStream
    ) -> Pin<Box<dyn Future<Output = IoResult<()>> + 'async_trait>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        Self: '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>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: '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>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: '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>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: '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>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn unix_listener_bind<'async_trait>(
        path: impl 'async_trait + AsRef<Path>
    ) -> Pin<Box<dyn Future<Output = IoResult<Self::UnixListener>> + 'async_trait>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    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>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        Self: '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

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

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

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

Required Methods

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

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.

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

Ok(0) means it prob cant take anymore.

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

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

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

Bind as a unix listening socket at the path

Accept one new connection

Implementors