timerfd-mio 0.1.0

Timerfd implementation for mio using rustix
Documentation
  • Coverage
  • 0%
    0 out of 18 items documented0 out of 13 items with examples
  • Size
  • Source code size: 23.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 965.1 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • louisbabeschneider/timerfd-mio
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • louisbabeschneider

timerfd-mio: A High-Precision Timer for Unix Systems

timerfd-mio is a Rust crate designed to provide a safe and ergonomic interface for managing high-precision timers on Unix systems. It leverages rustix for system-level operations and integrates seamlessly with mio for non-blocking I/O event polling.

Features

  • High-precision timers using the timerfd interface.
  • Safe and ergonomic Rust API.
  • Seamless integration with mio for non-blocking I/O.
  • Support for both one-shot and periodic timers.

Usage

Here's a quick example of how to use TimerFd:

use std::time::Duration;

fn main() {
    let mut poll = mio::Poll::new().unwrap();
    let mut events = mio::Events::with_capacity(2);

    /* Timer */
    let mut timer1 = timerfd_mio::TimerFd::new().unwrap();
    timer1.set_timeout_interval(Duration::from_millis(600), Duration::from_millis(300)).unwrap();
    poll.registry().register(&mut timer1, mio::Token(1), mio::Interest::READABLE).unwrap();

    let mut timer2 = timerfd_mio::TimerFd::new().unwrap();
    timer2.set_timeout_interval(Duration::from_millis(1000), Duration::from_millis(1000)).unwrap();
    poll.registry().register(&mut timer2, mio::Token(2), mio::Interest::READABLE).unwrap();

    loop {
        poll.poll(&mut events, None).unwrap();

        for event in &events {
            if event.token() == mio::Token(1) {
                timer1.read().unwrap();
                println!("Timer 1 event");
            }
            if event.token() == mio::Token(2) {
                // this function check timer overrun
                timer2.read_and_check_overrun().unwrap();
                println!("Timer 2 event");
            }
        }
    }
}

License

This project is licensed under the MIT License. See the LICENSE file for details.