pub fn send_tcp_ack(&mut self, dst: SocketAddrV4, src_port: u16) -> io::Result<()> {
        let key = (src_port, dst);

        if let None = self.tcp_cache2_map.get(&key) {
            return Ok(());
        }

        let cache2 = self.tcp_cache2_map.get_mut(&key).unwrap();
        let sequence = cache2.get_sequence();
        let window = *self.tcp_send_window_map.get(&key).unwrap_or(&0);
        if window > 0 {
            let cache = self
                .tcp_cache_map
                .entry(key)
                .or_insert_with(|| Cacher::new(sequence));
            let sent_size = cache.get_size();
            let remain_size = (window as usize).checked_sub(sent_size).unwrap_or(0);
            let remain_size = min(remain_size, u16::MAX as usize) as u16;

            let size = min(remain_size as usize, cache2.get_size());
            if size > 0 {
                let payload = cache2.get(size).unwrap();

                let sequence_tail = sequence
                    .checked_add(size as u32)
                    .unwrap_or_else(|| size as u32 - (u32::MAX - sequence));
                cache2.invalidate_to(sequence_tail);

                // Append to cache
                let cache = self
                    .tcp_cache_map
                    .entry(key)
                    .or_insert_with(|| Cacher::new(sequence));
                cache.append(&payload)?;

                // Send
                self.send_tcp_ack_raw(dst, src_port, sequence, &payload)?;
            }
        }

        Ok(())
    }
/// Sends TCP ACK packets from second (unsent) cache.
Sends TCP ACK packets from second (unsent) cache.
Sends TCP ACK packets from second ( unsent ) cache .
pub fn send_tcp_ack(&mut self, dst: SocketAddrV4, src_port: u16) -> io::Result<()> {
        let key = (src_port, dst);
        if let None = self.tcp_cache2_map.get(&key) {
            return Ok(());
        }
        let cache2 = self.tcp_cache2_map.get_mut(&key).unwrap();
        let sequence = cache2.get_sequence();
        let window = *self.tcp_send_window_map.get(&key).unwrap_or(&0);
        if window > 0 {
            let cache = self
                .tcp_cache_map
                .entry(key)
                .or_insert_with(|| Cacher::new(sequence));
            let sent_size = cache.get_size();
            let remain_size = (window as usize).checked_sub(sent_size).unwrap_or(0);
            let remain_size = min(remain_size, u16::MAX as usize) as u16;
            let size = min(remain_size as usize, cache2.get_size());
            if size > 0 {
                let payload = cache2.get(size).unwrap();
                let sequence_tail = sequence
                    .checked_add(size as u32)
                    .unwrap_or_else(|| size as u32 - (u32::MAX - sequence));
                cache2.invalidate_to(sequence_tail);
                // Append to cache
                let cache = self
                    .tcp_cache_map
                    .entry(key)
                    .or_insert_with(|| Cacher::new(sequence));
                cache.append(&payload)?;
                // Send
                self.send_tcp_ack_raw(dst, src_port, sequence, &payload)?;
            }
        }
        Ok(())
    }
pub fn send_tcp_ack ( & mut self , dst : SocketAddrV4 , src_port : u16 ) -> io :: Result < ( ) > { let key = ( src_port , dst ) ; if let None = self . tcp_cache2_map . get ( & key ) { return Ok ( ( ) ) ; } let cache2 = self . tcp_cache2_map . get_mut ( & key ) . unwrap ( ) ; let sequence = cache2 . get_sequence ( ) ; let window = * self . tcp_send_window_map . get ( & key ) . unwrap_or ( & 0 ) ; if window > 0 { let cache = self . tcp_cache_map . entry ( key ) . or_insert_with ( | | Cacher :: new ( sequence ) ) ; let sent_size = cache . get_size ( ) ; let remain_size = ( window as usize ) . checked_sub ( sent_size ) . unwrap_or ( 0 ) ; let remain_size = min ( remain_size , u16 :: MAX as usize ) as u16 ; let size = min ( remain_size as usize , cache2 . get_size ( ) ) ; if size > 0 { let payload = cache2 . get ( size ) . unwrap ( ) ; let sequence_tail = sequence . checked_add ( size as u32 ) . unwrap_or_else ( | | size as u32 - ( u32 :: MAX - sequence ) ) ; cache2 . invalidate_to ( sequence_tail ) ; // Append to cache let cache = self . tcp_cache_map . entry ( key ) . or_insert_with ( | | Cacher :: new ( sequence ) ) ; cache . append ( & payload ) ? ; // Send self . send_tcp_ack_raw ( dst , src_port , sequence , & payload ) ? ; } } Ok ( ( ) ) }
Sends TCP ACK packets from second (unsent) cache.
Sends TCP ACK packets from second ( unsent ) cache .
&mut self
dst
SocketAddrV4
src_port
u16