`Epoll::add` works differently comparing to `epoll::epoll_ctl`
slhmy opened this issue · comments
Hi, I'm trying to upgrade nix from 0.26 to 0.27, the one thing which bothered me is the new Epoll
.
I used to have a function add_epoll_fd
like:
fn add_epoll_fd(epoll_fd: RawFd, fd: RawFd) -> Result<(), JudgeCoreError> {
let mut event = EpollEvent::new(EpollFlags::EPOLLIN, fd as u64);
log::debug!("Adding fd={} to epoll", fd);
Ok(epoll_ctl(
epoll_fd,
EpollOp::EpollCtlAdd,
fd,
Some(&mut event),
)?)
}
// Then in 0.27 I did a bit change to make it still working
let epoll = Epoll::new(EpollCreateFlags::EPOLL_CLOEXEC)?;
add_epoll_fd(epoll.0 as RawFd, user_exit_read)?;
But when I changed epoll::epoll_ctl
to Epoll::add
, my epoll seems to be blocked:
fn add_epoll_fd(epoll: &Epoll, fd: RawFd) -> Result<(), JudgeCoreError> {
let event = EpollEvent::new(EpollFlags::EPOLLIN, fd as u64);
log::debug!("Adding fd={} to epoll", fd);
Ok(epoll.add(&eventfd(fd as u32, EfdFlags::empty())?, event)?)
}
let epoll = Epoll::new(EpollCreateFlags::EPOLL_CLOEXEC)?;
add_epoll_fd(&epoll, user_exit_read)?;
Closing this issue for I found eventfd
is a single one, I made a mistake!
For cases similar with me use unsafe { BorrowedFd::borrow_raw(fd) }
to convert RawFd
to AsFd impl
.