9个稳定版本
使用旧版Rust 2015
1.6.0 | 2024年3月21日 |
---|---|
1.5.0 | 2023年6月8日 |
1.4.1 | 2023年3月30日 |
1.4.0 | 2022年11月29日 |
0.2.0 | 2016年11月30日 |
#73 in Unix API
27,300 monthly downloads
用于 29 个crate (8 directly)
17KB
267 代码行数(不含注释)
rust-timerfd
Linux内核timerfd API的Rust接口。
lib.rs
:
Linux内核timerfd API的Rust接口。
示例
use timerfd::{TimerFd, TimerState, SetTimeFlags};
use std::time::Duration;
// Create a new timerfd
// (unwrap is actually fine here for most usecases)
let mut tfd = TimerFd::new().unwrap();
// The timer is initially disarmed
assert_eq!(tfd.get_state(), TimerState::Disarmed);
// Set the timer
tfd.set_state(TimerState::Oneshot(Duration::new(1, 0)), SetTimeFlags::Default);
// Observe that the timer is now set
match tfd.get_state() {
TimerState::Oneshot(d) => println!("Remaining: {:?}", d),
_ => unreachable!(),
}
// Wait for the remaining time
tfd.read();
// It was a oneshot timer, so it's now disarmed
assert_eq!(tfd.get_state(), TimerState::Disarmed);
用法
不幸的是,这个示例无法显示为什么最初会使用timerfd:因为它创建了一个可以与 select(2)
, poll(2)
和 epoll(2)
一起监视的文件描述符。
换句话说,与其他任何计时器实现相比,它提供的主要优势是实现了 AsFd
/AsRawFd
特性。
文件描述符在计时器到期时变为就绪/可读。
依赖项
~1.5–9.5MB
~95K SLoC