diff options
author | qupeng <onlyqupeng@gmail.com> | 2016-12-19 15:54:59 +0800 |
---|---|---|
committer | qupeng <onlyqupeng@gmail.com> | 2016-12-19 15:54:59 +0800 |
commit | acc15131bf445807025aa8d32b1aa925405705e2 (patch) | |
tree | 47f75d54b2dbc40b2ea872f5cf089cd129a1ea60 /src/sys | |
parent | 2d6ffc394f4016e79eaffac3c86b7188773077d8 (diff) | |
download | nix-acc15131bf445807025aa8d32b1aa925405705e2.zip |
fix all and update CHANGELOG.md
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/epoll.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 1f2054a1..eb28ffb9 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -3,6 +3,7 @@ use libc::{self, c_int}; use std::os::unix::io::RawFd; use std::ptr; use std::mem; +use ::Error; bitflags!( #[repr(C)] @@ -25,7 +26,7 @@ bitflags!( } ); -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Eq, PartialEq)] #[repr(C)] pub enum EpollOp { EpollCtlAdd = 1, @@ -91,8 +92,13 @@ pub fn epoll_create1(flags: EpollCreateFlags) -> Result<RawFd> { pub fn epoll_ctl<'a, T>(epfd: RawFd, op: EpollOp, fd: RawFd, event: T) -> Result<()> where T: Into<&'a mut EpollEvent> { - let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.into().event) }; - Errno::result(res).map(drop) + let event: &mut EpollEvent = event.into(); + if event as *const EpollEvent == ptr::null() && op != EpollOp::EpollCtlDel { + Err(Error::Sys(Errno::EINVAL)) + } else { + let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event) }; + Errno::result(res).map(drop) + } } #[inline] |