-
Notifications
You must be signed in to change notification settings - Fork 667
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
refactor: make Epoll take BorrowedFd #2232
base: master
Are you sure you want to change the base?
Conversation
#[repr(transparent)] | ||
pub struct Epoll<'fd> { | ||
epoll_fd: OwnedFd, | ||
_fds: std::marker::PhantomData<*mut &'fd ()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot use _fds: std::marker::PhantomData<BorrowedFd<'fd>>
here or the following code would compile without any issue:
use nix::sys::epoll::{Epoll, EpollCreateFlags, EpollEvent};
use nix::unistd::pipe;
fn main() {
let (r, _w) = pipe().unwrap();
let epoll = Epoll::new(EpollCreateFlags::empty()).unwrap();
epoll.add(r, EpollEvent::empty()).unwrap();
drop(r);
drop(epoll);
}
I haven't figured out the reason, but using an invariant type here would work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly ping @asomers, do you have any idea about this?
pub fn test_epoll_add_delete() { | ||
let epoll = Epoll::new(EpollCreateFlags::empty()).unwrap(); | ||
let event = EpollEvent::new(EpollFlags::EPOLLIN | EpollFlags::EPOLLERR, 1); | ||
let fd_1 = unsafe { BorrowedFd::borrow_raw(1) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to get rid of the unsafe, I suggest:
let fd_1 = unsafe { BorrowedFd::borrow_raw(1) }; | |
let stdin = std::io::stdin(); | |
let fd_1 = stdin.as_fd(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
What does this PR do
Epoll
-associated functions takeBorrowedFd
so that it is consistent withFdSet
andPollFd
test_epoll.rs
, use the new APIsChecklist:
CONTRIBUTING.md