From da36438f5bef8f885fb3ea9269b73ba85df32a07 Mon Sep 17 00:00:00 2001 From: Philipp Matthias Schaefer Date: Wed, 31 Aug 2016 21:05:35 +0200 Subject: [PATCH] Readd EpollEvent --- src/sys/epoll.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 9b30f993eb..2cdc663859 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -31,6 +31,18 @@ pub enum EpollOp { EpollCtlMod = 3 } +#[derive(Clone, Copy)] +#[repr(C)] +pub struct EpollEvent { + event: libc::epoll_event, +} + +impl EpollEvent { + fn new(events: EpollEventKind, data: u64) -> EpollEvent { + EpollEvent { event: libc::epoll_event { events: events.bits(), u64: data } } + } +} + #[inline] pub fn epoll_create() -> Result { let res = unsafe { libc::epoll_create(1024) }; @@ -46,16 +58,16 @@ pub fn epoll_create1(flags: c_int) -> Result { } #[inline] -pub fn epoll_ctl(epfd: RawFd, op: EpollOp, fd: RawFd, event: &mut libc::epoll_event) -> Result<()> { - let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, event as *mut libc::epoll_event) }; +pub fn epoll_ctl(epfd: RawFd, op: EpollOp, fd: RawFd, event: &mut EpollEvent) -> Result<()> { + let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event) }; Errno::result(res).map(drop) } #[inline] -pub fn epoll_wait(epfd: RawFd, events: &mut [libc::epoll_event], timeout_ms: isize) -> Result { +pub fn epoll_wait(epfd: RawFd, events: &mut [EpollEvent], timeout_ms: isize) -> Result { let res = unsafe { - libc::epoll_wait(epfd, events.as_mut_ptr(), events.len() as c_int, timeout_ms as c_int) + libc::epoll_wait(epfd, events.as_mut_ptr() as *mut libc::epoll_event, events.len() as c_int, timeout_ms as c_int) }; Errno::result(res).map(|r| r as usize)