pub async fn connect_timeout<A: ToSocketAddrs>(
        addr: A,
        duration: Duration,
    ) -> Result<TcpStream> {
        if duration.as_secs() == 0 && duration.subsec_nanos() == 0 {
            return Err(io::Error::new(
                io::ErrorKind::InvalidInput,
                "cannot set a 0 duration timeout",
            )
            .into());
        }

        let addr = addr.to_socket_addrs()?.next().unwrap();
        let (addr, socket) = make_tcp_socket(&addr)?;
        let reactor = crate::executor().reactor();
        let source = reactor.connect_timeout(socket.as_raw_fd(), addr, duration);

        // connect_timeout submits two sqes to io_uring: a connect sqe soft-linked
        // with a LINK_TIMEOUT sqe. If the timeout fires, the connect sqe fails with
        // ECANCELED. We map that error to TimedOut to match the standard library's API.
        source
            .collect_rw()
            .await
            .map_err(|err| match err.raw_os_error() {
                Some(libc::ECANCELED) => {
                    io::Error::new(io::ErrorKind::TimedOut, "connection timed out")
                }
                _ => err,
            })?;

        Ok(TcpStream {
            stream: GlommioStream::from(socket),
        })
    }
/// Creates a TCP connection to the specified address with a timeout.
///
/// It is an error to pass a zero `Duration` to this function.
///
/// Timeouts are implemented using `io_uring`'s `IORING_OP_LINK_TIMEOUT`.
///
/// # Examples
///
/// ```no_run
/// use glommio::{net::TcpStream, LocalExecutor};
///
/// use std::time::Duration;
///
/// let ex = LocalExecutor::default();
/// ex.run(async move {
///     TcpStream::connect_timeout("127.0.0.1:10000", Duration::from_secs(10))
///         .await
///         .unwrap();
/// })
/// ```
Creates a TCP connection to the specified address with a timeout.
It is an error to pass a zero `Duration` to this function.


Creates a TCP connection to the specified address with a timeout . It is an error to pass a zero ` Duration ` to this function .
pub async fn connect_timeout<A: ToSocketAddrs>(
        addr: A,
        duration: Duration,
    ) -> Result<TcpStream> {
        if duration.as_secs() == 0 && duration.subsec_nanos() == 0 {
            return Err(io::Error::new(
                io::ErrorKind::InvalidInput,
                "cannot set a 0 duration timeout",
            )
            .into());
        }
        let addr = addr.to_socket_addrs()?.next().unwrap();
        let (addr, socket) = make_tcp_socket(&addr)?;
        let reactor = crate::executor().reactor();
        let source = reactor.connect_timeout(socket.as_raw_fd(), addr, duration);
        // connect_timeout submits two sqes to io_uring: a connect sqe soft-linked
        // with a LINK_TIMEOUT sqe. If the timeout fires, the connect sqe fails with
        // ECANCELED. We map that error to TimedOut to match the standard library's API.
        source
            .collect_rw()
            .await
            .map_err(|err| match err.raw_os_error() {
                Some(libc::ECANCELED) => {
                    io::Error::new(io::ErrorKind::TimedOut, "connection timed out")
                }
                _ => err,
            })?;
        Ok(TcpStream {
            stream: GlommioStream::from(socket),
        })
    }
pub async fn connect_timeout < A : ToSocketAddrs > ( addr : A , duration : Duration , ) -> Result < TcpStream > { if duration . as_secs ( ) == 0 && duration . subsec_nanos ( ) == 0 { return Err ( io :: Error :: new ( io :: ErrorKind :: InvalidInput , " " , ) . into ( ) ) ; } let addr = addr . to_socket_addrs ( ) ? . next ( ) . unwrap ( ) ; let ( addr , socket ) = make_tcp_socket ( & addr ) ? ; let reactor = crate :: executor ( ) . reactor ( ) ; let source = reactor . connect_timeout ( socket . as_raw_fd ( ) , addr , duration ) ; // connect_timeout submits two sqes to io_uring: a connect sqe soft-linked // with a LINK_TIMEOUT sqe. If the timeout fires, the connect sqe fails with // ECANCELED. We map that error to TimedOut to match the standard library's API. source . collect_rw ( ) . await . map_err ( | err | match err . raw_os_error ( ) { Some ( libc :: ECANCELED ) => { io :: Error :: new ( io :: ErrorKind :: TimedOut , " " ) } _ => err , } ) ? ; Ok ( TcpStream { stream : GlommioStream :: from ( socket ) , } ) }
Creates a TCP connection to the specified address with a timeout.
Creates a TCP connection to the specified address with a timeout .
addr
A
duration
Duration
addr
A
duration
Duration
examples
```no_run
use glommio::{net::TcpStream, LocalExecutor}.

use std::time::Duration.


` ` ` no_run use glommio :: { net :: TcpStream LocalExecutor } . use std :: time :: Duration .