-
Notifications
You must be signed in to change notification settings - Fork 323
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
Implement epoll shim #3712
base: master
Are you sure you want to change the base?
Implement epoll shim #3712
Conversation
@rustbot author |
Co-authored-by: Oli Scherer <[email protected]>
Co-authored-by: Oli Scherer <[email protected]>
Co-authored-by: Oli Scherer <[email protected]>
fn test_pointer() { | ||
// Create an epoll instance. | ||
let epfd = unsafe { libc::epoll_create1(0) }; | ||
assert_ne!(epfd, -1); | ||
|
||
// Create a socketpair instance. | ||
let mut fds = [-1, -1]; | ||
let res = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) }; | ||
assert_eq!(res, 0); | ||
|
||
// Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET | ||
// EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32. | ||
let epollet = libc::EPOLLET as u32; | ||
let flags = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT | libc::EPOLLRDHUP).unwrap() | epollet; | ||
let data = MaybeUninit::<u64>::uninit().as_ptr(); | ||
let mut ev = libc::epoll_event { events: u32::try_from(flags).unwrap(), u64: data as u64 }; | ||
let res = unsafe { libc::epoll_ctl(epfd, libc::EPOLL_CTL_ADD, fds[1], &mut ev) }; | ||
assert_ne!(res, -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.
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.
The cast causes an integer address to be produced. I think this means it can't be turned back into an actual pointer, but that's ok since we don't have a use case for it yet.
I think libc
's epoll_event
type is wrong and should be using a union for the data field. I guess for now anyone using this could be using https://doc.rust-lang.org/std/ptr/fn.with_exposed_provenance.html to get back a pointer on some platforms.
We'll need to evaluate whether tokio needs to store pointers here, but we can delay that to later imo
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.
Without knowing the context here -- if epoll has to store something that is "either an integer or a pointer", then Scalar
would be the type to use, I think?
EDIT: Ah, postponing also works, as long as there is a comment in the code somewhere clarifying this.
let epollet = libc::EPOLLET as u32; | ||
let flags = u32::try_from(libc::EPOLLIN | libc::EPOLLOUT | libc::EPOLLRDHUP).unwrap() | epollet; | ||
let data = MaybeUninit::<u64>::uninit().as_ptr(); | ||
let mut ev = libc::epoll_event { events: u32::try_from(flags).unwrap(), u64: data as u64 }; |
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.
let mut ev = libc::epoll_event { events: u32::try_from(flags).unwrap(), u64: data as u64 }; | |
let mut ev = libc::epoll_event { events: u32::try_from(flags).unwrap(), u64: data.expose_provenance() as u64 }; |
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.
expose_provenance
is on nightly so error will be thrown when it is used. Is there any way to get around this?
Error:
error[E0658]: use of unstable library feature 'exposed_provenance'
--> ./tests/pass-dep/libc/libc-epoll.rs:292:19
|
292 | u64: data.expose_provenance() as u64,
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #95228 <https://github.com/rust-lang/rust/issues/95228> for more information
= help: add `#![feature(exposed_provenance)]` to the crate attributes to enable
= note: this compiler was built on 2024-07-06; consider upgrading it if it is out of date
error: aborting due to 1 previous error
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.
you can add the feature gate
…tion is inserted to two different epoll instance
This PR implements non-blocking
epoll
for #3448 . The design for this PR is documented in https://hackmd.io/@tiif/SJatftrH0 .