Implement I/O timeouts that specify the REALTIME clock. (#4777)
POSIX specifies that functions like `nanosleep` use the REALTIME clock, so allow WASI `poll_oneoff` calls to use the REALTIME clock, at least for non-absolute intervals. POSIX specifies that the timeouts should not be affected by subsequent `clock_settime` calls, so they behave the same way as MONOTONIC clock requests, so we can implement them as monotonic requests.
This commit is contained in:
@@ -1090,6 +1090,33 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
|||||||
sub.userdata.into(),
|
sub.userdata.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
types::Clockid::Realtime => {
|
||||||
|
// POSIX specifies that functions like `nanosleep` and others use the
|
||||||
|
// `REALTIME` clock. But it also says that `clock_settime` has no effect
|
||||||
|
// on threads waiting in these functions. MONOTONIC should always have
|
||||||
|
// resolution at least as good as REALTIME, so we can translate a
|
||||||
|
// non-absolute `REALTIME` request into a `MONOTONIC` request.
|
||||||
|
let clock = self.clocks.monotonic.deref();
|
||||||
|
let precision = Duration::from_nanos(clocksub.precision);
|
||||||
|
let duration = Duration::from_nanos(clocksub.timeout);
|
||||||
|
let deadline = if clocksub
|
||||||
|
.flags
|
||||||
|
.contains(types::Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME)
|
||||||
|
{
|
||||||
|
return Err(Error::not_supported());
|
||||||
|
} else {
|
||||||
|
clock
|
||||||
|
.now(precision)
|
||||||
|
.checked_add(duration)
|
||||||
|
.ok_or_else(|| Error::overflow().context("deadline"))?
|
||||||
|
};
|
||||||
|
poll.subscribe_monotonic_clock(
|
||||||
|
clock,
|
||||||
|
deadline,
|
||||||
|
precision,
|
||||||
|
sub.userdata.into(),
|
||||||
|
)
|
||||||
|
}
|
||||||
_ => Err(Error::invalid_argument()
|
_ => Err(Error::invalid_argument()
|
||||||
.context("timer subscriptions only support monotonic timer"))?,
|
.context("timer subscriptions only support monotonic timer"))?,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user