Adding an implementation for timerfd.#1261
Conversation
asomers-ax
left a comment
There was a problem hiding this comment.
This looks like a good start. But I think the interface could be more Rusty. Instead of requiring the user to read into a buffer that will be ignored, can you add a sleep method or something that does the read?
|
I addressed most of your comments in the latest commit I think. As for having a sleep method or equivalent, I think it is a fairly It is worth noting that reading on the If we indeed need a higher level interface then I would like to move away from the method names I have right now to make it clear that the semantics are different from the underlying syscalls. |
asomers
left a comment
There was a problem hiding this comment.
The changes look good. But I do think there needs to be a higher level interface than read. The goal is for the API to be as low-level as any Nix user will ever need, but no lower. Requiring the user to declare an empty buffer, for example, is too low.
|
I pushed a new set of changes including a slightly higher level interface. You now have 5 methods for the TimerFd: The idea is that you use I still feel somewhat uneasy about the Typically in the case of The name |
asomers
left a comment
There was a problem hiding this comment.
Looks good! Could you please add a CHANGELOG entry, too?
|
Ok, I added it to the changelog. |
|
Only one more problem: you'll have to rebase to fix the test failure. |
f7e1092 to
f3ab3a8
Compare
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 rust-lang/libc#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.
|
Ok, I rebased on top of master. |
|
Build succeeded: |
Hello,
I have encountered a situation where I needed to use timerfd in addition to other fd with nix implementation of epoll.
Here is a basic implementation of this feature, I also added some documentation and tests.
Note: currently testing works by pausing for 1-3 seconds. Obviously it is pretty bad if we want tests to run quickly but that was my best idea at the time. Feel free to suggest any other way.
Thank you!