Skip to content

Commit

Permalink
Avoid potential future panics with Sub::sub
Browse files Browse the repository at this point in the history
The docs for the implemetation of Sub for Instant state that the
operation currently saturates but future versions may reintroduce
panics.
  • Loading branch information
sirhcel committed Sep 1, 2024
1 parent 7291f2f commit 8847a52
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/posix/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::io;
use std::os::unix::io::RawFd;
use std::slice;
use std::time::Duration;
use std::time::{Duration, Instant};

use nix::libc::c_int;
use nix::poll::{PollFd, PollFlags};
Expand All @@ -24,10 +24,10 @@ fn wait_fd(fd: RawFd, events: PollFlags, timeout: Duration) -> io::Result<()> {
use nix::errno::Errno::{EIO, EPIPE};

let mut fd = PollFd::new(fd, events);
let end = std::time::Instant::now() + timeout;
let end = Instant::now() + timeout;
let wait;
loop {
wait = match poll_clamped(&mut fd, end - std::time::Instant::now()) {
wait = match poll_clamped(&mut fd, end.saturating_duration_since(Instant::now())) {
Ok(r) => r,
Err(nix::Error::EINTR) => continue,
Err(nix::Error::EAGAIN) => continue,
Expand Down

0 comments on commit 8847a52

Please sign in to comment.