pub(super) fn connect(
        host: StreamAddress,
        connect_timeout: Option<Duration>,
        tls_options: Option<TlsOptions>,
    ) -> Result<Self> {
        let timeout = connect_timeout.unwrap_or(DEFAULT_CONNECT_TIMEOUT);

        // The URI options spec requires that the default is 10 seconds, but that 0 should indicate
        // no timeout.
        let inner = if timeout == Duration::from_secs(0) {
            TcpStream::connect(&host)?
        } else {
            let mut socket_addrs: Vec<_> = host.to_socket_addrs()?.collect();
            socket_addrs.sort_by_key(|addr| if addr.is_ipv4() { 0 } else { 1 });

            TcpStream::connect_timeout(&socket_addrs[0], timeout)?
        };
        inner.set_nodelay(true)?;
        let inner = inner;

        match tls_options {
            Some(cfg) => {
                let name = DNSNameRef::try_from_ascii_str(&host.hostname)?;
                let mut tls_config = cfg.into_rustls_config()?;
                tls_config.enable_sni = true;

                let session = rustls::ClientSession::new(&Arc::new(tls_config), name);

                Ok(Stream::Tls(BufStream::new(rustls::StreamOwned::new(
                    session, inner,
                ))))
            }
            None => Ok(Self::Tcp(BufStream::new(inner))),
        }
    }
/// Creates a new stream connected to `address`.
Creates a new stream connected to `address`.
Creates a new stream connected to ` address ` .
pub(super) fn connect(
        host: StreamAddress,
        connect_timeout: Option<Duration>,
        tls_options: Option<TlsOptions>,
    ) -> Result<Self> {
        let timeout = connect_timeout.unwrap_or(DEFAULT_CONNECT_TIMEOUT);
        // The URI options spec requires that the default is 10 seconds, but that 0 should indicate
        // no timeout.
        let inner = if timeout == Duration::from_secs(0) {
            TcpStream::connect(&host)?
        } else {
            let mut socket_addrs: Vec<_> = host.to_socket_addrs()?.collect();
            socket_addrs.sort_by_key(|addr| if addr.is_ipv4() { 0 } else { 1 });
            TcpStream::connect_timeout(&socket_addrs[0], timeout)?
        };
        inner.set_nodelay(true)?;
        let inner = inner;
        match tls_options {
            Some(cfg) => {
                let name = DNSNameRef::try_from_ascii_str(&host.hostname)?;
                let mut tls_config = cfg.into_rustls_config()?;
                tls_config.enable_sni = true;
                let session = rustls::ClientSession::new(&Arc::new(tls_config), name);
                Ok(Stream::Tls(BufStream::new(rustls::StreamOwned::new(
                    session, inner,
                ))))
            }
            None => Ok(Self::Tcp(BufStream::new(inner))),
        }
    }
pub ( super ) fn connect ( host : StreamAddress , connect_timeout : Option < Duration > , tls_options : Option < TlsOptions > , ) -> Result < Self > { let timeout = connect_timeout . unwrap_or ( DEFAULT_CONNECT_TIMEOUT ) ; // The URI options spec requires that the default is 10 seconds, but that 0 should indicate // no timeout. let inner = if timeout == Duration :: from_secs ( 0 ) { TcpStream :: connect ( & host ) ? } else { let mut socket_addrs : Vec < _ > = host . to_socket_addrs ( ) ? . collect ( ) ; socket_addrs . sort_by_key ( | addr | if addr . is_ipv4 ( ) { 0 } else { 1 } ) ; TcpStream :: connect_timeout ( & socket_addrs [ 0 ] , timeout ) ? } ; inner . set_nodelay ( true ) ? ; let inner = inner ; match tls_options { Some ( cfg ) => { let name = DNSNameRef :: try_from_ascii_str ( & host . hostname ) ? ; let mut tls_config = cfg . into_rustls_config ( ) ? ; tls_config . enable_sni = true ; let session = rustls :: ClientSession :: new ( & Arc :: new ( tls_config ) , name ) ; Ok ( Stream :: Tls ( BufStream :: new ( rustls :: StreamOwned :: new ( session , inner , ) ) ) ) } None => Ok ( Self :: Tcp ( BufStream :: new ( inner ) ) ) , } }
Creates a new stream connected to `address`.
Creates a new stream connected to ` address ` .
host
StreamAddress
connect_timeout
Option<Duration>
tls_options
Option<TlsOptions>
host
StreamAddress
connect_timeout
Option<Duration>
tls_options
Option<TlsOptions>