summaryrefslogtreecommitdiff
path: root/src/sys/time.rs
diff options
context:
space:
mode:
authorVincent Dagonneau <vincent.dagonneau@ssi.gouv.fr>2020-03-03 16:30:30 +0100
committerVincent Dagonneau <vincent.dagonneau@ssi.gouv.fr>2020-07-07 14:29:11 +0200
commitf3bd6ed8116b89cbe6dfb3c942048dae09375685 (patch)
treeca502b7e7b760e241f2daab16ccb28c9a5d61d7d /src/sys/time.rs
parent4b6b14a0c2fabb0cdedf415aa0eece2752adc47e (diff)
downloadnix-f3bd6ed8116b89cbe6dfb3c942048dae09375685.zip
Adding an implementation and some basic tests for timerfd.
Removed support for timerfd on Android as it seems to have been deprecated? See https://android.googlesource.com/platform/development/+/73a5a3b/ndk/platforms/android-20/include/sys/timerfd.h or https://github.com/rust-lang/libc/issues/1589 Removed the public status of `TimerSpec`, as it should not be exposed to the user. Implemented `FromRawFd` for `TimerFd` as it already implements `AsRawFd`. Addressed comments from the latest code review: - Removed upper bound assertions on timer expirations in tests. - Made the main example runnable and added code to show how to wait for the timer. - Refactored `ClockId` to use `libc_enum`. - Added comments for all public parts of the module. - Wrapped to 80 cols. - Changed the size of the buffer in the tests to the minimum required. * Ran rustfmt. * Added a `From` implementation for `libc::timespec` -> `TimeSpec`. * Reworked the example with the new changes and changed the timer from 5 to 1 second. * Added a constructor for a 0-initialized `TimerSpec`. * Added a new method to get the timer configured expiration (based on timerfd_gettime). * Added an helper method to unset the expiration of the timer. * Added a `wait` method to actually read from the timer. * Renamed `settime` into just `set`. * Refactored the tests and added a new one that tests both the `unset` and the `get` method. Modified CHANGELOG.
Diffstat (limited to 'src/sys/time.rs')
-rw-r--r--src/sys/time.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/sys/time.rs b/src/sys/time.rs
index 51baa9e1..973a3526 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -60,6 +60,11 @@ const TS_MAX_SECONDS: i64 = ::std::isize::MAX as i64;
const TS_MIN_SECONDS: i64 = -TS_MAX_SECONDS;
+impl From<timespec> for TimeSpec {
+ fn from(ts: timespec) -> Self {
+ Self(ts)
+ }
+}
impl AsRef<timespec> for TimeSpec {
fn as_ref(&self) -> &timespec {