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;
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>
where
'life0: 'async_trait,
'life1: 'async_trait,
Self: '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
'life0: 'async_trait,
'life1: 'async_trait,
Self: '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
The type for the TCP connections returned by Self::connect()
.
type 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
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.
fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: '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
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Open a TCP listener on a given socket address.