Use explicit Timeout enum instead of magic constants

The FdReadableSet api was always intended to be converted to use Duration
instead of usec/msec once the ffi was removed. This lets us be explicit about
forever/infinite timeouts and removes the (small) chance of a collision between
u64::MAX and INFINITE.

I tried this out with `type Timeout = Option<Duration>` (only without the alias)
but was unhappy with easy it is to accidentally use `None` when you meant a
timeout of zero.
This commit is contained in:
Mahmoud Al-Qudsi
2025-01-04 18:22:38 -06:00
parent 83eb25d45f
commit b4e8cc8b79
6 changed files with 67 additions and 61 deletions

View File

@@ -5,7 +5,7 @@
str2wcstring, write_loop, WSL,
};
use crate::env::{EnvStack, Environment};
use crate::fd_readable_set::FdReadableSet;
use crate::fd_readable_set::{FdReadableSet, Timeout};
use crate::flog::{FloggableDebug, FLOG};
use crate::fork_exec::flog_safe::FLOG_SAFE;
use crate::global_safety::RelaxedAtomicBool;
@@ -334,9 +334,9 @@ fn readb(in_fd: RawFd, blocking: bool) -> ReadbResult {
// Here's where we call select().
let select_res = fdset.check_readable(if blocking {
FdReadableSet::kNoTimeout
Timeout::Forever
} else {
0
Timeout::ZERO
});
if select_res < 0 {
let err = errno::errno().0;