Struct ClockSyncer

Source
pub struct ClockSyncer { /* private fields */ }
Expand description

Stores the state of the source PTP clock (i.e., an open file descriptor to it), and provides ClockSyncer::sync to set on-demand the system-wide real-time (i.e., wall-clock time) clock to the time of that source PTP clock.

Implementations§

Source§

impl ClockSyncer

Source

pub fn with_ptp_clock(dev_ptp_path: impl AsRef<Path>) -> Result<Self, Error>

Create a new ClockSyncer, assuming the provided dev_ptp_path is the path to the device node (typically under /dev/) that refers to the source PTP clock.

§Errors
  • On failure to open(2) the provided source PTP clock device node.
§Notes

It is up to the caller to provide a path to a device node that refers to a valid instance of a PTP clock. This is not checked upon ClockSyncer initialization, and failure to provide so will be manifested through Error::Clock errors in subsequent ClockSyncer::sync calls.

The auxiliary function verify_ptp_dev attempts to verify whether a path refers to a device node that corresponds to a PTP clock device.

Use ClockSyncer::with_kvm_clock (which calls find_ptp_kvm) to attempt to automatically find a device node of KVM’s paravirtualized PTP clock before constructing the ClockSyncer.

Source

pub fn with_kvm_clock() -> Result<Self, Error>

Create a new ClockSyncer, by searching for the KVM PTP clock to be used as the source.

§Errors
  • On failure while looking for the KVM PTP clock via find_ptp_kvm.
  • On failure to open(2) the KVM PTP clock device node via with_ptp_clock.
Source

pub fn sync(&self) -> Result<(), Error>

Set the system-wide real-time clock to the time provided by the source PTP clock of this ClockSyncer.

§Errors
  • If clock_gettime(2) fails for the source PTP clock.
  • If clock_settime(2) fails for the system-wide real-time clock.
Source

pub fn try_clone(&self) -> Result<Self, Error>

Attempt to clone the ClockSyncer, by also dup(2)ing the underlying file descriptor of source PTP clock.

§Errors

If OwnedFd::try_clone fails.

§Panics

If dup(2) returns an error value not in [1, 4095].

Trait Implementations§

Source§

impl Debug for ClockSyncer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more