fn rate_limited_rx_single_frame(&mut self) -> bool {
        // If limiter.consume() fails it means there is no more TokenType::Ops
        // budget and rate limiting is in effect.
        if !self.rx_rate_limiter.consume(1, TokenType::Ops) {
            METRICS.net.rx_rate_limiter_throttled.inc();
            return false;
        }
        // If limiter.consume() fails it means there is no more TokenType::Bytes
        // budget and rate limiting is in effect.
        if !self
            .rx_rate_limiter
            .consume(self.rx_bytes_read as u64, TokenType::Bytes)
        {
            // revert the OPS consume()
            self.rx_rate_limiter.manual_replenish(1, TokenType::Ops);
            METRICS.net.rx_rate_limiter_throttled.inc();
            return false;
        }

        // Attempt frame delivery.
        let success = self.write_frame_to_guest();

        // Undo the tokens consumption if guest delivery failed.
        if !success {
            // revert the OPS consume()
            self.rx_rate_limiter.manual_replenish(1, TokenType::Ops);
            // revert the BYTES consume()
            self.rx_rate_limiter
                .manual_replenish(self.rx_bytes_read as u64, TokenType::Bytes);
        }
        success
    }
// Attempts to copy a single frame into the guest if there is enough
// rate limiting budget.
// Returns true on successful frame delivery.
Attempts to copy a single frame into the guest if there is enough
rate limiting budget.
Returns true on successful frame delivery.
Attempts to copy a single frame into the guest if there is enough rate limiting budget . Returns true on successful frame delivery .
fn rate_limited_rx_single_frame(&mut self) -> bool {
        // If limiter.consume() fails it means there is no more TokenType::Ops
        // budget and rate limiting is in effect.
        if !self.rx_rate_limiter.consume(1, TokenType::Ops) {
            METRICS.net.rx_rate_limiter_throttled.inc();
            return false;
        }
        // If limiter.consume() fails it means there is no more TokenType::Bytes
        // budget and rate limiting is in effect.
        if !self
            .rx_rate_limiter
            .consume(self.rx_bytes_read as u64, TokenType::Bytes)
        {
            // revert the OPS consume()
            self.rx_rate_limiter.manual_replenish(1, TokenType::Ops);
            METRICS.net.rx_rate_limiter_throttled.inc();
            return false;
        }
        // Attempt frame delivery.
        let success = self.write_frame_to_guest();
        // Undo the tokens consumption if guest delivery failed.
        if !success {
            // revert the OPS consume()
            self.rx_rate_limiter.manual_replenish(1, TokenType::Ops);
            // revert the BYTES consume()
            self.rx_rate_limiter
                .manual_replenish(self.rx_bytes_read as u64, TokenType::Bytes);
        }
        success
    }
fn rate_limited_rx_single_frame ( & mut self ) -> bool { // If limiter.consume() fails it means there is no more TokenType::Ops // budget and rate limiting is in effect. if ! self . rx_rate_limiter . consume ( 1 , TokenType :: Ops ) { METRICS . net . rx_rate_limiter_throttled . inc ( ) ; return false ; } // If limiter.consume() fails it means there is no more TokenType::Bytes // budget and rate limiting is in effect. if ! self . rx_rate_limiter . consume ( self . rx_bytes_read as u64 , TokenType :: Bytes ) { // revert the OPS consume() self . rx_rate_limiter . manual_replenish ( 1 , TokenType :: Ops ) ; METRICS . net . rx_rate_limiter_throttled . inc ( ) ; return false ; } // Attempt frame delivery. let success = self . write_frame_to_guest ( ) ; // Undo the tokens consumption if guest delivery failed. if ! success { // revert the OPS consume() self . rx_rate_limiter . manual_replenish ( 1 , TokenType :: Ops ) ; // revert the BYTES consume() self . rx_rate_limiter . manual_replenish ( self . rx_bytes_read as u64 , TokenType :: Bytes ) ; } success }
Attempts to copy a single frame into the guest if there is enough
rate limiting budget.
Attempts to copy a single frame into the guest if there is enough rate limiting budget .
&mut self
&mut self