0 | module System.Linux.Timerfd
 1 |
 2 | import System.Linux.Timerfd.Prim as P
 3 |
 4 |
 5 | import public Data.C.Ptr
 6 | import public System.Linux.Timerfd.Flags
 7 | import public System.Linux.Timerfd.Timerfd
 8 | import public System.Posix.File
 9 | import public System.Posix.Timer
10 |
11 | %default total
12 |
13 | ||| Opens a new `timerfd` file descriptor for observing the given clock.
14 | |||
15 | ||| Notes:
16 | ||| * A `timerfd` should be closed using `close` just like other file
17 | |||   descriptors.
18 | ||| * In general, use `readTimerfd` instead of the `read` functions
19 | |||   from `System.Posix.File` to read from a `timerfd`.
20 | export %inline
21 | timerfd : Has Errno es => EIO1 f => ClockId -> TimerfdFlags -> f es Timerfd
22 | timerfd c fs = elift1 (P.timerfd c fs)
23 |
24 | ||| Sets the time of a `timerfd`.
25 | |||
26 | ||| The currently set time will be stored in `old`.
27 | ||| Use the `TFD_TIMER_ABSTIME` flag if the time should be interpreted as
28 | ||| an absolute wall clock time.
29 | export %inline
30 | setitime : Has Errno es => EIO1 f => Timerfd -> Bits32 -> (new,old : IOTimerspec) -> f es ()
31 | setitime t f new old = elift1 (P.setitime t f new old)
32 |
33 | ||| Reads the currently set `itimerspec` of a `timerfd` and uses the given
34 | ||| pointer to place the data.
35 | export %inline
36 | getitime : HasIO io => Timerfd -> (old : IOTimerspec) -> io ()
37 | getitime t = primIO . P.getitime t
38 |
39 | ||| Reads data from a `timerfd`.
40 | |||
41 | ||| This will block until the next time the timer expires unless `TFD_NONBLOCK`
42 | ||| was set when creating the timer.
43 | |||
44 | ||| The value returned is the number of times the timer expired since
45 | ||| the last read.
46 | export %inline
47 | readTimerfd : Has Errno es => EIO1 f => Timerfd -> f es Bits64
48 | readTimerfd fd = elift1 (P.readTimerfd fd)
49 |
50 | --------------------------------------------------------------------------------
51 | -- Convenience API
52 | --------------------------------------------------------------------------------
53 |
54 | ||| Like `setitime` but without storing the currently set `itimerspec`.
55 | export %inline
56 | setTime : Has Errno es => EIO1 f => Timerfd -> Bits32 -> Timerspec -> f es ()
57 | setTime t f n = elift1 (P.setTime t f n)
58 |
59 | ||| Convenience alias for `getitime`.
60 | export %inline
61 | getTime : Has Errno es => EIO1 f => Timerfd -> f es Timerspec
62 | getTime fd = elift1 (P.getTime fd)
63 |