Skip to content

Commit bde15cf

Browse files
committed
improve std lib linux epoll API
1 parent 72ca2b2 commit bde15cf

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

std/os/linux/index.zig

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ pub const TIOCGPKT = 0x80045438;
329329
pub const TIOCGPTLCK = 0x80045439;
330330
pub const TIOCGEXCL = 0x80045440;
331331

332+
pub const EPOLL_CLOEXEC = O_CLOEXEC;
333+
332334
pub const EPOLL_CTL_ADD = 1;
333335
pub const EPOLL_CTL_DEL = 2;
334336
pub const EPOLL_CTL_MOD = 3;
@@ -751,22 +753,31 @@ pub fn fstat(fd: i32, stat_buf: &Stat) usize {
751753
return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf));
752754
}
753755

754-
pub const epoll_data = u64;
756+
pub const epoll_data = extern union {
757+
ptr: usize,
758+
fd: i32,
759+
@"u32": u32,
760+
@"u64": u64,
761+
};
755762

756763
pub const epoll_event = extern struct {
757764
events: u32,
758-
data: epoll_data
765+
data: epoll_data,
759766
};
760767

761768
pub fn epoll_create() usize {
762-
return arch.syscall1(arch.SYS_epoll_create, usize(1));
769+
return epoll_create1(0);
770+
}
771+
772+
pub fn epoll_create1(flags: usize) usize {
773+
return arch.syscall1(arch.SYS_epoll_create1, flags);
763774
}
764775

765776
pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) usize {
766777
return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
767778
}
768779

769-
pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) usize {
780+
pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: u32, timeout: i32) usize {
770781
return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
771782
}
772783

std/os/linux/test.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test "timer" {
2525

2626
var event = linux.epoll_event {
2727
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
28-
.data = 0
28+
.data = linux.epoll_data { .ptr = 0 },
2929
};
3030

3131
err = linux.epoll_ctl(i32(epoll_fd), linux.EPOLL_CTL_ADD, i32(timer_fd), &event);

0 commit comments

Comments
 (0)