Struct nix::sys::timerfd::TimerFd[][src]

pub struct TimerFd { /* fields omitted */ }
Expand description

A timerfd instance. This is also a file descriptor, you can feed it to other interfaces consuming file descriptors, epoll for example.

Implementations

impl TimerFd[src]

pub fn new(clockid: ClockId, flags: TimerFlags) -> Result<Self>[src]

Creates a new timer based on the clock defined by clockid. The underlying fd can be assigned specific flags with flags (CLOEXEC, NONBLOCK). The underlying fd will be closed on drop.

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

Sets 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 disables 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 disables the alarm altogether.

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

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

pub fn unset(&self) -> Result<()>[src]

Remove the alarm if any is set.

pub fn wait(&self) -> Result<()>[src]

Wait for the configured alarm to expire.

Note: If the alarm is unset, then you will wait forever.

Trait Implementations

impl AsRawFd for TimerFd[src]

fn as_raw_fd(&self) -> RawFd[src]

Extracts the raw file descriptor. Read more

impl Debug for TimerFd[src]

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

Formats the value using the given formatter. Read more

impl Drop for TimerFd[src]

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

impl FromRawFd for TimerFd[src]

unsafe fn from_raw_fd(fd: RawFd) -> Self[src]

Constructs a new instance of Self from the given raw file descriptor. Read more

Auto Trait Implementations

impl RefUnwindSafe for TimerFd

impl Send for TimerFd

impl Sync for TimerFd

impl Unpin for TimerFd

impl UnwindSafe for TimerFd

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.