Struct nix::sys::timer::Timer

source ·
pub struct Timer(/* private fields */);
Expand description

A Unix signal per-process timer.

Implementations§

source§

impl Timer

source

pub fn new(clockid: ClockId, sigevent: SigEvent) -> Result<Self>

Creates a new timer based on the clock defined by clockid. The details of the signal and its handler are defined by the passed sigevent.

source

pub fn set( &mut self, expiration: Expiration, flags: TimerSetTimeFlags, ) -> Result<()>

Set a new alarm on the timer.

§Types of alarm

There are 3 types of alarms you can set:

  • one shot: the alarm will trigger once after the specified amount of time. Example: I want an alarm to go off in 60s and then disable itself.

  • interval: the alarm will trigger every specified interval of time. Example: I want an alarm to go off every 60s. The alarm will first go off 60s after I set it and every 60s after that. The alarm will not disable itself.

  • interval delayed: the alarm will trigger after a certain amount of time and then trigger at a specified interval. Example: I want an alarm to go off every 60s but only start in 1h. The alarm will first trigger 1h after I set it and then every 60s after that. The alarm will not disable itself.

§Relative vs absolute alarm

If you do not set any TimerSetTimeFlags, then the TimeSpec you pass to the Expiration you want is relative. If however you want an alarm to go off at a certain point in time, you can set TFD_TIMER_ABSTIME. Then the one shot TimeSpec and the delay TimeSpec of the delayed interval are going to be interpreted as absolute.

§Disabling alarms

Note: Only one alarm can be set for any given timer. Setting a new alarm actually removes the previous one.

Note: Setting a one shot alarm with a 0s TimeSpec disable the alarm altogether.

source

pub fn get(&self) -> Result<Option<Expiration>>

Get the parameters for the alarm currently set, if any.

source

pub fn overruns(&self) -> i32

Return the number of timers that have overrun

Each timer is able to queue one signal to the process at a time, meaning if the signal is not handled before the next expiration the timer has ‘overrun’. This function returns how many times that has happened to this timer, up to libc::DELAYTIMER_MAX. If more than the maximum number of overruns have happened the return is capped to the maximum.

Trait Implementations§

source§

impl Debug for Timer

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for Timer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Timer

§

impl RefUnwindSafe for Timer

§

impl !Send for Timer

§

impl !Sync for Timer

§

impl Unpin for Timer

§

impl UnwindSafe for Timer

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, 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.