MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / event_handler

Method event_handler

rate_limiter/src/lib.rs:459–483  ·  view source on GitHub ↗

This function needs to be called every time there is an event on the FD provided by this object's `AsRawFd` trait implementation. # Errors If the rate limiter is disabled or is not blocked, an error is returned.

(&self)

Source from the content-addressed store, hash-verified

457 ///
458 /// If the rate limiter is disabled or is not blocked, an error is returned.
459 pub fn event_handler(&self) -> Result<(), Error> {
460 let mut guard = self.inner.lock().unwrap();
461 loop {
462 // Note: As we manually added the `O_NONBLOCK` flag to the FD, the following
463 // `timer_fd::wait()` won't block (which is different from its default behavior.)
464 match guard.timer_fd.wait() {
465 Err(e) => {
466 let err: std::io::Error = e.into();
467 match err.kind() {
468 std::io::ErrorKind::Interrupted => (),
469 std::io::ErrorKind::WouldBlock => {
470 return Err(Error::SpuriousRateLimiterEvent(
471 "Rate limiter event handler called without a present timer",
472 ));
473 }
474 _ => return Err(Error::TimerFdWaitError(err)),
475 }
476 }
477 _ => {
478 self.timer_active.store(false, Ordering::Relaxed);
479 return Ok(());
480 }
481 }
482 }
483 }
484
485 /// Updates the parameters of the token buckets associated with this RateLimiter.
486 // TODO: Please note that, right now, the buckets become full after being updated.

Callers 7

test_rate_limiter_opsFunction · 0.45
test_rate_limiter_fullFunction · 0.45
handle_eventMethod · 0.45
handle_eventMethod · 0.45

Calls 2

waitMethod · 0.80
kindMethod · 0.80

Tested by 5

test_rate_limiter_opsFunction · 0.36
test_rate_limiter_fullFunction · 0.36