async fn accept(&mut self) -> crate::Result<TcpStream> {
        let mut backoff = 1;

        loop {
            // Perform the accept operation. If a socket is successfully accepted, return it.
            // Otherwise, save the error.
            match self.listener.accept().await {
                Ok((socket, _)) => return Ok(socket),
                Err(err) => {
                    // If accept has failed too many times. Return the error.
                    debug!("failed to accept connection: {}", err);
                    if backoff > 4 {
                        return Err(err.into());
                    }
                }
            }

            // Pause execution until the back off period elapses.
            time::sleep(Duration::from_secs(backoff)).await;

            // Increment the back off
            backoff += 1;
        }
    }
/// Accept an inbound connection.
///
/// Errors are handled by backing off and retrying. An incremental backoff strategy is used.
/// After the first failure, the task waits for 1 second. After the second failure, the task
/// waits for 2 seconds. Each subsequent failure increases the wait time by 1 second. If
/// accepting fails on the 5th try after waiting for 4 seconds, an error is returned.
Accept an inbound connection.
Errors are handled by backing off and retrying. An incremental backoff strategy is used.
After the first failure, the task waits for 1 second. After the second failure, the task
waits for 2 seconds. Each subsequent failure increases the wait time by 1 second. If
accepting fails on the 5th try after waiting for 4 seconds, an error is returned.
Accept an inbound connection . Errors are handled by backing off and retrying . An incremental backoff strategy is used . After the first failure the task waits for 1 second . After the second failure the task waits for 2 seconds . Each subsequent failure increases the wait time by 1 second . If accepting fails on the 5th try after waiting for 4 seconds an error is returned .
async fn accept(&mut self) -> crate::Result<TcpStream> {
        let mut backoff = 1;
        loop {
            // Perform the accept operation. If a socket is successfully accepted, return it.
            // Otherwise, save the error.
            match self.listener.accept().await {
                Ok((socket, _)) => return Ok(socket),
                Err(err) => {
                    // If accept has failed too many times. Return the error.
                    debug!("failed to accept connection: {}", err);
                    if backoff > 4 {
                        return Err(err.into());
                    }
                }
            }
            // Pause execution until the back off period elapses.
            time::sleep(Duration::from_secs(backoff)).await;
            // Increment the back off
            backoff += 1;
        }
    }
async fn accept ( & mut self ) -> crate :: Result < TcpStream > { let mut backoff = 1 ; loop { // Perform the accept operation. If a socket is successfully accepted, return it. // Otherwise, save the error. match self . listener . accept ( ) . await { Ok ( ( socket , _ ) ) => return Ok ( socket ) , Err ( err ) => { // If accept has failed too many times. Return the error. debug ! ( " " err ) ; if backoff > 4 { return Err ( err . into ( ) ) ; } } } // Pause execution until the back off period elapses. time :: sleep ( Duration :: from_secs ( backoff ) ) . await ; // Increment the back off backoff += 1 ; } }
Accept an inbound connection.
Accept an inbound connection .
&mut self
&mut self