pub fn send(&mut self, packet_size: usize, now: Instant) {
        if self.rate == 0 {
            self.reset(now);

            return;
        }

        if !self.iv.is_zero() {
            self.next_time = self.next_time.max(now) + self.iv;

            self.iv = Duration::ZERO;
        }

        let interval =
            Duration::from_secs_f64(self.capacity as f64 / self.rate as f64);

        let elapsed = now.saturating_duration_since(self.last_update);

        // if too old, reset it.
        if elapsed > interval {
            self.reset(now);
        }

        self.used += packet_size;

        let same_size = if let Some(last_packet_size) = self.last_packet_size {
            last_packet_size == packet_size
        } else {
            true
        };

        self.last_packet_size = Some(packet_size);

        if self.used >= self.capacity || !same_size {
            self.iv =
                Duration::from_secs_f64(self.used as f64 / self.rate as f64);

            self.used = 0;

            self.last_update = now;

            self.last_packet_size = None;
        };
    }
// Update the timestamp to sent.
Update the timestamp to sent.
Update the timestamp to sent .
pub fn send(&mut self, packet_size: usize, now: Instant) {
        if self.rate == 0 {
            self.reset(now);
            return;
        }
        if !self.iv.is_zero() {
            self.next_time = self.next_time.max(now) + self.iv;
            self.iv = Duration::ZERO;
        }
        let interval =
            Duration::from_secs_f64(self.capacity as f64 / self.rate as f64);
        let elapsed = now.saturating_duration_since(self.last_update);
        // if too old, reset it.
        if elapsed > interval {
            self.reset(now);
        }
        self.used += packet_size;
        let same_size = if let Some(last_packet_size) = self.last_packet_size {
            last_packet_size == packet_size
        } else {
            true
        };
        self.last_packet_size = Some(packet_size);
        if self.used >= self.capacity || !same_size {
            self.iv =
                Duration::from_secs_f64(self.used as f64 / self.rate as f64);
            self.used = 0;
            self.last_update = now;
            self.last_packet_size = None;
        };
    }
pub fn send ( & mut self , packet_size : usize , now : Instant ) { if self . rate == 0 { self . reset ( now ) ; return ; } if ! self . iv . is_zero ( ) { self . next_time = self . next_time . max ( now ) + self . iv ; self . iv = Duration :: ZERO ; } let interval = Duration :: from_secs_f64 ( self . capacity as f64 / self . rate as f64 ) ; let elapsed = now . saturating_duration_since ( self . last_update ) ; // if too old, reset it. if elapsed > interval { self . reset ( now ) ; } self . used += packet_size ; let same_size = if let Some ( last_packet_size ) = self . last_packet_size { last_packet_size == packet_size } else { true } ; self . last_packet_size = Some ( packet_size ) ; if self . used >= self . capacity || ! same_size { self . iv = Duration :: from_secs_f64 ( self . used as f64 / self . rate as f64 ) ; self . used = 0 ; self . last_update = now ; self . last_packet_size = None ; } ; }
Update the timestamp to sent.
Update the timestamp to sent .
&mut self
packet_size
usize
now
Instant
&mut self
packet_size
usize
now
Instant