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)
| 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. |