Skip to main content

NetStreamProvider

Trait NetStreamProvider 

Source
pub(crate) trait NetStreamProvider<ADDR = SocketAddr>:
    Clone
    + Send
    + Sync
    + 'static {
    type Stream: AsyncRead + AsyncWrite + StreamOps + Send + Sync + Unpin + 'static;
    type Listener: NetStreamListener<ADDR, Stream = Self::Stream> + Send + Sync + Unpin + 'static;
    type ConnectOptions: Clone + Default + Send + Sync + Unpin + 'static;
    type ListenOptions: Clone + Default + Send + Sync + Unpin + 'static;

    // Required methods
    fn connect<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        addr: &'life1 ADDR,
        options: &'life2 Self::ConnectOptions,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Stream, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn listen<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        addr: &'life1 ADDR,
        options: &'life2 Self::ListenOptions,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
}
Expand description

Trait for a runtime that can create and accept connections over network sockets.

(In Arti we use the AsyncRead and AsyncWrite traits from futures::io as more standard, even though the ones from Tokio can be a bit more efficient. Let’s hope that they converge in the future.)

Required Associated Types§

Source

type Stream: AsyncRead + AsyncWrite + StreamOps + Send + Sync + Unpin + 'static

The type for the connections returned by Self::connect().

Source

type Listener: NetStreamListener<ADDR, Stream = Self::Stream> + Send + Sync + Unpin + 'static

The type for the listeners returned by Self::listen().

Source

type ConnectOptions: Clone + Default + Send + Sync + Unpin + 'static

The options that can be passed to Self::connect().

It can include options set with setsockopt, as well as options that influence higher layers (eg, the runtime).

For connected streams, you can use StreamOps to perform additional operations or to configure additional options.

Source

type ListenOptions: Clone + Default + Send + Sync + Unpin + 'static

The options that can be passed to Self::listen().

This includes both options that affect the listening, and options that will apply to any individual accepted connection streams.

It can include options set with setsockopt, as well as options that influence higher layers (eg, the runtime).

For established streams that are accepted from a listener, you can use StreamOps to perform additional operations or to configure additional options.

Required Methods§

Source

fn connect<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, addr: &'life1 ADDR, options: &'life2 Self::ConnectOptions, ) -> Pin<Box<dyn Future<Output = Result<Self::Stream, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Launch a connection connection to a given socket address.

Note that unlike std::net:TcpStream::connect, we do not accept any types other than a single ADDR. We do this because we must be absolutely sure not to perform unnecessary DNS lookups.

Source

fn listen<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, addr: &'life1 ADDR, options: &'life2 Self::ListenOptions, ) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Open a listener on a given socket address.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl NetStreamProvider for AsyncStd

Source§

type Stream = TcpStream

Source§

type Listener = TcpListener

Source§

type ConnectOptions = TcpConnectOptions

Source§

type ListenOptions = TcpListenOptions

Source§

fn connect<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, options: &'life2 <AsyncStd as NetStreamProvider>::ConnectOptions, ) -> Pin<Box<dyn Future<Output = Result<<AsyncStd as NetStreamProvider>::Stream, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, AsyncStd: 'async_trait,

Source§

fn listen<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, options: &'life2 <AsyncStd as NetStreamProvider>::ListenOptions, ) -> Pin<Box<dyn Future<Output = Result<<AsyncStd as NetStreamProvider>::Listener, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, AsyncStd: 'async_trait,

Source§

impl NetStreamProvider<SocketAddr> for AsyncStd

Source§

type Stream = UnixStream

Source§

type Listener = UnixListener

Source§

type ConnectOptions = UnixConnectOptions

Source§

type ListenOptions = UnixListenOptions

Source§

fn connect<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, options: &'life2 <AsyncStd as NetStreamProvider<SocketAddr>>::ConnectOptions, ) -> Pin<Box<dyn Future<Output = Result<<AsyncStd as NetStreamProvider<SocketAddr>>::Stream, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, AsyncStd: 'async_trait,

Source§

fn listen<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, options: &'life2 <AsyncStd as NetStreamProvider<SocketAddr>>::ListenOptions, ) -> Pin<Box<dyn Future<Output = Result<<AsyncStd as NetStreamProvider<SocketAddr>>::Listener, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, AsyncStd: 'async_trait,

Implementors§

Source§

impl NetStreamProvider for AsyncStdNativeTlsRuntime

Source§

impl NetStreamProvider for AsyncStdRustlsRuntime

Source§

impl NetStreamProvider for MockNetProvider

Source§

impl NetStreamProvider for MockRuntime

Source§

impl NetStreamProvider for PreferredRuntime

Source§

impl NetStreamProvider for SmolNativeTlsRuntime

Source§

impl NetStreamProvider for SmolRustlsRuntime

Source§

impl NetStreamProvider for TokioNativeTlsRuntime

Source§

impl NetStreamProvider for TokioRustlsRuntime

Source§

impl NetStreamProvider<SocketAddr> for AsyncStdNativeTlsRuntime

Source§

impl NetStreamProvider<SocketAddr> for AsyncStdRustlsRuntime

Source§

impl NetStreamProvider<SocketAddr> for MockRuntime

Source§

impl NetStreamProvider<SocketAddr> for PreferredRuntime

Source§

impl NetStreamProvider<SocketAddr> for SmolNativeTlsRuntime

Source§

impl NetStreamProvider<SocketAddr> for SmolRustlsRuntime

Source§

impl NetStreamProvider<SocketAddr> for TokioNativeTlsRuntime

Source§

impl NetStreamProvider<SocketAddr> for TokioRustlsRuntime

Source§

impl<R: Runtime> NetStreamProvider for MockNetRuntime<R>

Source§

impl<R: Runtime> NetStreamProvider for MockSleepRuntime<R>

Source§

impl<R: Runtime> NetStreamProvider<SocketAddr> for MockNetRuntime<R>

Source§

impl<R: Runtime> NetStreamProvider<SocketAddr> for MockSleepRuntime<R>

Source§

impl<T> NetStreamProvider<SocketAddr> for T

Source§

impl<TaskR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR> NetStreamProvider for CompoundRuntime<TaskR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR>
where TcpR: NetStreamProvider + Send + Sync + 'static, TaskR: Send + Sync + 'static, SleepR: Send + Sync + 'static, CoarseTimeR: Send + Sync + 'static, UnixR: Clone + Send + Sync + 'static, TlsR: Send + Sync + 'static, UdpR: Send + Sync + 'static,

Source§

impl<TaskR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR> NetStreamProvider<SocketAddr> for CompoundRuntime<TaskR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR>
where UnixR: NetStreamProvider<SocketAddr> + Clone + Send + Sync + 'static, TaskR: Send + Sync + 'static, SleepR: Send + Sync + 'static, CoarseTimeR: Send + Sync + 'static, TcpR: Send + Sync + 'static, TlsR: Send + Sync + 'static, UdpR: Send + Sync + 'static,