Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round up when converting timeout to ms for epoll_wait() #1615

Merged
merged 3 commits into from Sep 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/sys/unix/selector/epoll.rs
Expand Up @@ -87,7 +87,19 @@ impl Selector {
const MAX_SAFE_TIMEOUT: u128 = libc::c_int::max_value() as u128;

let timeout = timeout
.map(|to| cmp::min(to.as_millis(), MAX_SAFE_TIMEOUT) as libc::c_int)
.map(|to| {
let to_ms = to.as_millis();
// as_millis() truncates, so round up to 1 ms as the documentation says can happen.
// This avoids turning submillisecond timeouts into immediate returns unless the
// caller explicitly requests that by specifying a zero timeout.
let to_ms = to_ms
+ if to_ms == 0 && to.subsec_nanos() != 0 {
1
} else {
0
};
cmp::min(MAX_SAFE_TIMEOUT, to_ms) as libc::c_int
})
.unwrap_or(-1);

events.clear();
Expand Down