Skip to content

Commit

Permalink
Fix timeouts
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Oct 22, 2023
1 parent bee0eea commit b6262d9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use std::marker::PhantomData;
use std::num::NonZeroUsize;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
use std::time::Duration;
use std::time::{Duration, Instant};

use cfg_if::cfg_if;

Expand Down Expand Up @@ -646,12 +646,18 @@ impl Poller {
/// poller.delete(&socket)?;
/// # std::io::Result::Ok(())
/// ```
pub fn wait(&self, events: &mut Events, timeout: Option<Duration>) -> io::Result<usize> {
pub fn wait(&self, events: &mut Events, mut timeout: Option<Duration>) -> io::Result<usize> {

This comment has been minimized.

Copy link
@fogti

fogti Oct 22, 2023

Member

why is this mut?

This comment has been minimized.

Copy link
@notgull

notgull Oct 23, 2023

Author Member

Mistake, fixed!

let span = tracing::trace_span!("Poller::wait", ?timeout);
let _enter = span.enter();

if let Ok(_lock) = self.lock.try_lock() {
let deadline = timeout.and_then(|timeout| Instant::now().checked_add(timeout));

loop {
// Figure out how long to wait for.
let timeout =
deadline.map(|deadline| deadline.saturating_duration_since(Instant::now()));

// Wait for I/O events.
if let Err(e) = self.poller.wait(&mut events.events, timeout) {
// If the wait was interrupted by a signal, clear events and try again.
Expand Down

0 comments on commit b6262d9

Please sign in to comment.