Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix epoll bug #802

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ pub fn epoll_ctl<'a, T>(epfd: RawFd, op: EpollOp, fd: RawFd, event: T) -> Result
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)
println!("libc::epoll_ctl returned {:?}", res);
let retval = Errno::result(res).map(drop);
println!("in epoll_ctl, retval is {:?}", retval);
retval
}
}

Expand Down
16 changes: 11 additions & 5 deletions test/sys/test_epoll.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use nix::sys::epoll::{EpollCreateFlags, EpollOp, EpollEvent};
use nix::sys::epoll::{EPOLLIN, EPOLLERR};
use nix::sys::epoll::{epoll_create1, epoll_ctl};
use nix::{Error, Errno};
use nix::{Error, Errno, Result};

#[test]
pub fn test_epoll_errno() {
let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
let efd = epoll_create1(EpollCreateFlags::empty()).expect("epoll_create1 failed");
let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None);
assert!(result.is_err());
assert_eq!(result.unwrap_err(), Error::Sys(Errno::ENOENT));
Expand All @@ -17,8 +17,14 @@ pub fn test_epoll_errno() {

#[test]
pub fn test_epoll_ctl() {
let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
let ok : Result<()> = Ok(());
let notok: Result<()> = Err(Error::Sys(Errno::UnknownErrno));
println!("In test_epoll_ctl, ok is {:?}, notok is {:?}", ok, notok);

let efd = epoll_create1(EpollCreateFlags::empty()).expect("epoll_create1 failed");
let mut event = EpollEvent::new(EPOLLIN | EPOLLERR, 1);
epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event).unwrap();
epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).unwrap();
let epoll_ctl_res = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event);
println!("In test_epoll_ctl, result was {:?}", epoll_ctl_res);
epoll_ctl_res.expect("epoll_ctl 1 failed");
epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).expect("epoll_ctl 2 failed");
}