Trait tor_rtcompat::TcpProvider
source · pub trait TcpProvider: Clone + Send + Sync + 'static {
type TcpStream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static;
type TcpListener: TcpListener<TcpStream = Self::TcpStream> + Send + Sync + Unpin + 'static;
// Required methods
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}
Expand description
Trait for a runtime that can create and accept TCP connections.
(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§
sourcetype TcpStream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static
type TcpStream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static
The type for the TCP connections returned by Self::connect()
.
sourcetype TcpListener: TcpListener<TcpStream = Self::TcpStream> + Send + Sync + Unpin + 'static
type TcpListener: TcpListener<TcpStream = Self::TcpStream> + Send + Sync + Unpin + 'static
The type for the TCP listeners returned by Self::listen()
.
Required Methods§
sourcefn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Launch a TCP connection to a given socket address.
Note that unlike std::net:TcpStream::connect
, we do not accept
any types other than a single SocketAddr
. We do this because,
as a Tor implementation, we most be absolutely sure not to perform
unnecessary DNS lookups.
sourcefn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Open a TCP listener on a given socket address.
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl TcpProvider for AsyncStd
Available on (crate features native-tls
or rustls
) and (crate features async-std
or tokio
) and crate feature async-std
only.
impl TcpProvider for AsyncStd
Available on (crate features
native-tls
or rustls
) and (crate features async-std
or tokio
) and crate feature async-std
only.type TcpStream = TcpStream
type TcpListener = TcpListener
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Implementors§
source§impl TcpProvider for AsyncStdNativeTlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature async-std
only.
impl TcpProvider for AsyncStdNativeTlsRuntime
Available on (crate features
native-tls
or rustls
) and crate feature async-std
only.type TcpStream = <CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider, AsyncStd> as TcpProvider>::TcpStream
type TcpListener = <CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, NativeTlsProvider, AsyncStd> as TcpProvider>::TcpListener
source§impl TcpProvider for AsyncStdRustlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature async-std
only.
impl TcpProvider for AsyncStdRustlsRuntime
Available on (crate features
native-tls
or rustls
) and crate feature async-std
only.type TcpStream = <CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, RustlsProvider, AsyncStd> as TcpProvider>::TcpStream
type TcpListener = <CompoundRuntime<AsyncStd, AsyncStd, AsyncStd, RustlsProvider, AsyncStd> as TcpProvider>::TcpListener
source§impl TcpProvider for PreferredRuntime
impl TcpProvider for PreferredRuntime
type TcpStream = <TokioNativeTlsRuntime as TcpProvider>::TcpStream
type TcpListener = <TokioNativeTlsRuntime as TcpProvider>::TcpListener
source§impl TcpProvider for TokioNativeTlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature tokio
only.
impl TcpProvider for TokioNativeTlsRuntime
Available on (crate features
native-tls
or rustls
) and crate feature tokio
only.type TcpStream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as TcpProvider>::TcpStream
type TcpListener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as TcpProvider>::TcpListener
source§impl TcpProvider for TokioRustlsRuntime
Available on (crate features native-tls
or rustls
) and crate feature tokio
only.
impl TcpProvider for TokioRustlsRuntime
Available on (crate features
native-tls
or rustls
) and crate feature tokio
only.