(
ctx: &VmCtx,
sub_clock: SubscriptionClock,
precision: u64,
min_timeout: &mut Option<Timestamp>,
timeouts: &mut Vec<(u64, Timestamp)>,
userdata: u64,
)
| 20 | #[external_methods(push, checked_sub, try_into, subscription_clock_abstime)] |
| 21 | #[external_calls(Some)] |
| 22 | pub fn poll_parse_clock( |
| 23 | ctx: &VmCtx, |
| 24 | sub_clock: SubscriptionClock, |
| 25 | precision: u64, |
| 26 | min_timeout: &mut Option<Timestamp>, |
| 27 | timeouts: &mut Vec<(u64, Timestamp)>, |
| 28 | userdata: u64, |
| 29 | ) -> RuntimeResult<()> { |
| 30 | // if the subscription is a clock, check if it is the shortest timeout. |
| 31 | // let clock = subscription_clock.id; |
| 32 | match sub_clock.id.try_into()? { |
| 33 | // TODO: what clock source does posix poll use for timeouts? Will a relative |
| 34 | // realtime be significantly different than monotonic? |
| 35 | ClockId::Monotonic | ClockId::Realtime => { |
| 36 | let now = wasi_clock_time_get(ctx, sub_clock.id, precision)?; |
| 37 | let timeout: Timestamp = if sub_clock.flags.subscription_clock_abstime() { |
| 38 | // if this is an absolute timeout, we need to wait the difference |
| 39 | // between now and the timeout |
| 40 | // This will also perform a checked cast to an i32, which will |
| 41 | sub_clock.timeout.checked_sub(now).ok_or(Eoverflow)? |
| 42 | } else { |
| 43 | sub_clock.timeout |
| 44 | }; |
| 45 | |
| 46 | if let Some(m_timeout) = min_timeout { |
| 47 | if timeout < *m_timeout { |
| 48 | *min_timeout = Some(timeout); |
| 49 | } |
| 50 | } else { |
| 51 | *min_timeout = Some(timeout); |
| 52 | } |
| 53 | |
| 54 | timeouts.push((userdata, timeout)); |
| 55 | Ok(()) |
| 56 | } |
| 57 | // we don't support timeouts on other clock types |
| 58 | _ => { |
| 59 | return Err(Einval); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #[with_ghost_var(trace: &mut Trace)] |
| 65 | #[requires(ctx_safe(ctx))] |
no test coverage detected