summaryrefslogtreecommitdiff
path: root/src/sys/time.rs
AgeCommit message (Collapse)Author
2023-05-20timerfd: Add TFD_TIMER_CANCEL_ON_SET flagAndrii Pohrebniak
2022-12-04Fix clippy lintsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-28Update use of libc::timespec to prepare for future libc versionWesley Wiser
In a future release of the `libc` crate, `libc::timespec` will contain private padding fields on `*-linux-musl` targets and so the struct will no longer be able to be created using the literal initialization syntax. Update places where `libc::timespec` is created to first zero initialize the value and then update the `tv_sec` and `tv_nsec` fields manually. Many of these places are in `const fn`s so a helper function `zero_init_timespec()` is introduced to help with this as `std::mem::MaybeUninit::zeroed()` is not a `const` function. Some matches on `libc::timespec` are also updated to include a trailing `..` pattern which works when `libc::timespec` has additional, private fields as well as when it does not (like for `x86_64-unknown-linux-gnu`).
2022-10-08Fix clippy warnings on nightlyRyan Zoeller
Clippy is now smarter about detecting unnecessary casts and useless conversions, which means we need to be more explicit about when the conversions are needed for a subset of platforms. Required changes found by repeatedly running the following command against a list of the supported platforms. `xargs -t -I {} sh -c "cargo clippy -Zbuild-std --target {} --all-targets -- -D warnings || exit 255"` I removed the casts it complained about, and then restored them with an `#[allow]` if a later target needed the cast.
2022-08-20fix microsecond calculation for TimeSpecS.J.R. van Schaik
2022-08-09remove deprecated itemsSteveLauC
2022-08-09format codeSteveLauC
2022-08-09remove deprecated itemsSteveLauC
2022-07-10Add const constructors for TimeSpec and TimeValAlan Somers
These are basically the same as From<libc::timespec> and From<libc::timeval>, but they're const and require less typing.
2022-06-24Fix all formating problems to pass CI formating testCostin-Robert Sin
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-05-29Clippy cleanup for latest nightlyAlan Somers
2021-12-30Introduce timer_* supportBrian L. Troutwine
This commit adds support for the signal timer mechanism in POSIX, the mirror to timerfd on Linux. Resolves #1424 Signed-off-by: Brian L. Troutwine <brian@troutwine.us>
2021-07-24Constify many functionsAlan Somers
Constify most functions that can be constified. The exceptions are mostly accessors for structs that have no const constructor.
2021-07-13Enable creating a const TimeSpecDaniel Dulaney
Previously, there was no way to create a TimeSpec in a const context because all creation was through traits. This adds two utility functions to create a const TimeSpec from a libc::timespec or a std::time::Duration
2021-02-15Port timespec to x32наб
2020-11-15Suppress time_t musl "deprecation"Tamir Duberstein
See https://github.com/rust-lang/libc/issues/1848 in which this type is changing from i32 to i64; the change is being announced via this deprecation.
2020-09-28Added clock_gettime, clock_getres, clock_settime, clock_getcpuclockidDaniil Bondarev
2020-07-07Adding an implementation and some basic tests for timerfd.Vincent Dagonneau
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.
2020-05-16Apply `repr(transparent)` to several FFI typesAlan Somers
repr(transparent) is required in order to safely cast between an FFI type and its NewType. This commit applies that attribute to PollFd, EpollEvent, IpMembershipRequest, Ipv6MembershipRequest, TimeVal, and IoVec. Fixes #1241
2020-04-26Support sendmmsg/recvmmsgGleb Pomykalov
2019-08-29Clippy cleanupAlan Somers
2019-06-09Add extra traits for all typesBryant Mairs
Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all traits are supported by all types, which is why many are missing some.
2019-02-14Fix misaligned references when using recvmsg with control messagesAlan Somers
On some platforms the alignment of cmsg_data could be less than the alignment of the messages that it contains. That led to unaligned reads on those platforms. This change fixes the issue by always copying the message contents into aligned objects. The change is not 100% backwards compatible when using recvmsg. Users may have to replace code like this: ```rust if let ControlMessage::ScmRights(&fds) = cmsg { ``` with this: ```rust if let ControlMessageOwned::ScmRights(fds) = cmsg { ``` Fixes #999
2018-12-08Replace try! with ?Alan Somers
try! is not available in Rust 2018
2018-11-07Make sys::time::{time_t, suseconds_t} publicJulio Merino
This allows handling the return values of other public functions (such as TimeVal's tv_sec and tv_usec) without having to pull in these types from libc (which is ugly if a project is trying to use nix exclusively to avoid libc's unsafety).
2018-01-28Deny unused qualificationsBryant Mairs
2016-12-16Add POSIX AIO supportAlan Somers
POSIX AIO is a standard for asynchronous file I/O. Read, write, and fsync operations can all take place in the background, with completion notification delivered by a signal, by a new thread, by kqueue, or not at all. This commit supports all standard AIO functions. However, lio_listio is disabled on macos because it doesn't seem to work, even though the syscall is present. The SigEvent class, used for AIO notifications among other things, is also added. Also, impl AsRef for TimeVal and TimeSpec
2016-11-25Fix use-after-free in selectAlan Somers
Also, fix the TimeSpec::cmp and TimeVal::cmp methods, and fix some formatting
2016-11-19Add TimeSpec, a Newtype around libc::timespecAlan Somers
Also, add trait TimeValLike, so some code can be shared between TimeSpec and TimeVal.
2016-11-19Make TimeVal a NewTypeAlan Somers
2016-11-19Opaqueify TimeValAlan Somers
By exposing its members, nix allowed users to create denormalized TimeVals, which don't work with the derived() Eq and Ord methods. Better to make TimeVal opaque, so it will always be normalized.
2015-04-20Fix build on Rust nightliesCarl Lerche
2015-04-01Remove usage of std::num::IntCarl Lerche
2015-03-16Fix on 32bit platformsCarl Lerche
2015-03-12Add TimeVal and helpersCarl Lerche