/// Send Ping request with sequence number.
Send Ping request with sequence number.
Send Ping request with sequence number .
pub async fn ping(&self, seq_cnt: u16) -> Result<(EchoReply, Duration)> {
        let sender = self.socket.clone();
        let mut packet = EchoRequest::new(self.host, self.ident, seq_cnt, self.size).encode()?;
        let sock_addr = SocketAddr::new(self.host, 0);
        let ident = self.ident;
        let cache = self.cache.clone();
        task::spawn(async move {
            let _size = sender
                .send_to(&mut packet, &sock_addr.into())
                .await
                .expect("socket send packet error");
            cache.insert(ident, seq_cnt, Instant::now());
        });
        tokio::select! {
            reply = self.recv_reply(seq_cnt) => {
                reply.map_err(|err| {
                    self.cache.remove(ident, seq_cnt);
                    err
                })
            },
            _ = sleep(self.timeout) => {
                self.cache.remove(ident, seq_cnt);
                Err(SurgeError::Timeout)
            },
        }
    }
pub async fn ping ( & self , seq_cnt : u16 ) -> Result < ( EchoReply , Duration ) > { let sender = self . socket . clone ( ) ; let mut packet = EchoRequest :: new ( self . host , self . ident , seq_cnt , self . size ) . encode ( ) ? ; let sock_addr = SocketAddr :: new ( self . host , 0 ) ; let ident = self . ident ; let cache = self . cache . clone ( ) ; task :: spawn ( async move { let _size = sender . send_to ( & mut packet , & sock_addr . into ( ) ) . await . expect ( " " ) ; cache . insert ( ident , seq_cnt , Instant :: now ( ) ) ; } ) ; tokio :: select ! { reply self recv_reply ( seq_cnt ) { reply map_err ( err { self cache remove ( ident seq_cnt ) err } ) } sleep ( self timeout ) { self cache remove ( ident seq_cnt ) Err ( SurgeError Timeout ) } } }
Send Ping request with sequence number.
Send Ping request with sequence number .
&self
seq_cnt
u16