2018-02-05 06:26:39 -08:00
|
|
|
const std = @import("../../index.zig");
|
2018-04-22 10:24:25 -07:00
|
|
|
const builtin = @import("builtin");
|
2017-11-10 15:12:46 -08:00
|
|
|
const linux = std.os.linux;
|
|
|
|
const assert = std.debug.assert;
|
|
|
|
|
|
|
|
test "timer" {
|
|
|
|
const epoll_fd = linux.epoll_create();
|
|
|
|
var err = linux.getErrno(epoll_fd);
|
|
|
|
assert(err == 0);
|
|
|
|
|
|
|
|
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
|
|
|
|
assert(linux.getErrno(timer_fd) == 0);
|
|
|
|
|
2018-05-28 17:23:55 -07:00
|
|
|
const time_interval = linux.timespec{
|
2017-11-10 15:12:46 -08:00
|
|
|
.tv_sec = 0,
|
2018-05-28 17:23:55 -07:00
|
|
|
.tv_nsec = 2000000,
|
2017-11-10 15:12:46 -08:00
|
|
|
};
|
|
|
|
|
2018-05-28 17:23:55 -07:00
|
|
|
const new_time = linux.itimerspec{
|
2017-11-10 15:12:46 -08:00
|
|
|
.it_interval = time_interval,
|
2018-05-28 17:23:55 -07:00
|
|
|
.it_value = time_interval,
|
2017-11-10 15:12:46 -08:00
|
|
|
};
|
|
|
|
|
2018-06-16 23:57:07 -07:00
|
|
|
err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
|
2017-11-10 15:12:46 -08:00
|
|
|
assert(err == 0);
|
|
|
|
|
2018-05-28 17:23:55 -07:00
|
|
|
var event = linux.epoll_event{
|
2017-11-10 15:12:46 -08:00
|
|
|
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
|
2018-05-28 17:23:55 -07:00
|
|
|
.data = linux.epoll_data{ .ptr = 0 },
|
2017-11-10 15:12:46 -08:00
|
|
|
};
|
|
|
|
|
2018-06-16 23:57:07 -07:00
|
|
|
err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
|
2017-11-10 15:12:46 -08:00
|
|
|
assert(err == 0);
|
|
|
|
|
|
|
|
const events_one: linux.epoll_event = undefined;
|
|
|
|
var events = []linux.epoll_event{events_one} ** 8;
|
|
|
|
|
2018-06-03 22:09:15 -07:00
|
|
|
// TODO implicit cast from *[N]T to [*]T
|
2018-06-16 23:57:07 -07:00
|
|
|
err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
|
2017-11-10 15:12:46 -08:00
|
|
|
}
|