Read the current time, but with a bound on accuracy and a status. Returns a pair of (earliest, latest) timespec between which current time exists. The interval width is twice the clock error bound (ceb) such that: (earliest, latest) = ((now - ceb), (now + ceb)) The function also returns a clock status to assert that the clock is being synchronized, or free-running, or ... # Errors Returns [`Clo
(&mut self)
| 90 | /// # Errors |
| 91 | /// Returns [`ClockBoundError`] if the shared memory segments cannot be open or accessed. |
| 92 | pub fn now(&mut self) -> Result<ClockBoundNowResult, ClockBoundError> { |
| 93 | // The very first thing to do is to read from the ClockBound shared memory segment, take a |
| 94 | // snapshot to obtain the clock parameters and bound on error, and create a timestamp. |
| 95 | let cb_snap = self.clockbound_shm.snapshot()?; |
| 96 | let mut clock_bound_now_result = cb_snap.now()?; |
| 97 | |
| 98 | // Now that the timestamp is created, check whether the clockbound daemon has been |
| 99 | // restarted and the option to enable the clock disruption support has been turned on. If |
| 100 | // so, need to create a reader for the VMClock device shared memory. |
| 101 | if self.vmclock_shm.vmclock_shm_reader.is_none() |
| 102 | && cb_snap.clock_disruption_support_enabled() |
| 103 | { |
| 104 | self.vmclock_shm.vmclock_shm_reader = Some(VMClockShmReader::new( |
| 105 | self.vmclock_shm.vmclock_shm_path.as_str(), |
| 106 | )?); |
| 107 | } |
| 108 | |
| 109 | // Check whether the clock is disrupted. If the support to capture the clock disruption |
| 110 | // signal has been explicitly disabled, there is nothing to do. Otherwise, and if the |
| 111 | // VMClock shared memory is successfully read, this compares the value of the disruption |
| 112 | // marker between the clockbound daemon and the VMClock. If these disagree, a disruption |
| 113 | // has occured, and the clockbound daemon has not recovered from it yet. |
| 114 | let is_disrupted = match self.vmclock_shm.disruption_marker()? { |
| 115 | Some(marker) => marker != cb_snap.disruption_marker(), |
| 116 | None => false, |
| 117 | }; |
| 118 | |
| 119 | // If the clock is disrupted, overwrite the status |
| 120 | if is_disrupted { |
| 121 | clock_bound_now_result.clock_status = ClockStatus::Disrupted; |
| 122 | } |
| 123 | |
| 124 | Ok(clock_bound_now_result) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /// `ClockBoundSHM` handles access to the shared memory segment populated by the ClockBound daemon. |