pub struct Connection { /* private fields */ }Expand description
Wrapper around a ConnectionReader and ConnectionWriter to read and write on a network
connection.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn tcp_client<A: ToSocketAddrs + Display>(ip_addrs: A) -> Result<Self>
pub async fn tcp_client<A: ToSocketAddrs + Display>(ip_addrs: A) -> Result<Self>
Creates a Connection that uses a TCP transport.
§Example
Please see the tcp-client example program for a more thorough showcase.
Basic usage:
let mut conn = Connection::tcp_client("127.0.0.1:3456").await?;Source§impl Connection
impl Connection
Sourcepub async fn tls_client<A: ToSocketAddrs + Display>(
ip_addrs: A,
domain: &str,
connector: TlsConnector,
) -> Result<Self>
pub async fn tls_client<A: ToSocketAddrs + Display>( ip_addrs: A, domain: &str, connector: TlsConnector, ) -> Result<Self>
Creates a Connection that uses a TLS transport.
§Example
Please see the tls-client example program for a more thorough showcase.
Basic usage:
let mut conn = Connection::tls_client("127.0.0.1:3456", "localhost", client_config.into()).await?;Source§impl Connection
impl Connection
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Get the local IP address and port.
Sourcepub fn peer_addr(&self) -> SocketAddr
pub fn peer_addr(&self) -> SocketAddr
Get the peer IP address and port.
Sourcepub fn split(self) -> (ConnectionReader, ConnectionWriter)
pub fn split(self) -> (ConnectionReader, ConnectionWriter)
Consume the Connection to split into separate ConnectionReader and
ConnectionWriter halves.
Connections are split when reading and writing must be concurrent operations.
Sourcepub fn join(reader: ConnectionReader, writer: ConnectionWriter) -> Self
pub fn join(reader: ConnectionReader, writer: ConnectionWriter) -> Self
Re-wrap the ConnectionReader and ConnectionWriter halves into a Connection.
Sourcepub fn reader(&mut self) -> &mut ConnectionReader
pub fn reader(&mut self) -> &mut ConnectionReader
Get mutable access to the underlying ConnectionReader.
Sourcepub fn writer(&mut self) -> &mut ConnectionWriter
pub fn writer(&mut self) -> &mut ConnectionWriter
Get mutable access to the underlying ConnectionWriter.
Sourcepub async fn close(self) -> SocketAddr
pub async fn close(self) -> SocketAddr
Close the connection by closing both the reading and writing halves.
Trait Implementations§
Source§impl From<TcpStream> for Connection
impl From<TcpStream> for Connection
Source§impl From<TlsConnectionMetadata> for Connection
impl From<TlsConnectionMetadata> for Connection
Source§fn from(metadata: TlsConnectionMetadata) -> Self
fn from(metadata: TlsConnectionMetadata) -> Self
Creates a Connection using a TLS transport from TlsConnectionMetadata.