summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorqupeng <onlyqupeng@gmail.com>2016-12-19 15:54:59 +0800
committerqupeng <onlyqupeng@gmail.com>2016-12-19 15:54:59 +0800
commitacc15131bf445807025aa8d32b1aa925405705e2 (patch)
tree47f75d54b2dbc40b2ea872f5cf089cd129a1ea60 /src/sys
parent2d6ffc394f4016e79eaffac3c86b7188773077d8 (diff)
downloadnix-acc15131bf445807025aa8d32b1aa925405705e2.zip
fix all and update CHANGELOG.md
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/epoll.rs12
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]