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

FD handling: avoid unnecessary dynamic downcasts #4114

Merged
merged 2 commits into from
Dec 28, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Dec 28, 2024

The eventfd and socket implementations had to work with a FileDescriptionRef and then dynamically downcast it to the right type. That should be unnecessary, we should be able to just track what the actual type of these references is.

So that's what this PR implements: we now have FileDescriptionRef<T> where T indicates the type of the FD. We also have DynFileDescriptionRef for when the underlying type is not statically known. What makes this tricky is that we want to also have an FdId available via the reference. We can use CoercePointee to make Rc<(FdId, T)> a dyn-compatible pointer type that can be the receiver of read/write/close. However, that's still not quite enough since we also want dynamic downcasting, and that is only possible with Rc<dyn Any>, so the usual "make Any a supertrait" does not work... we need FdIdWith<Self>: Any, which doesn't work with supertrait upcasting so it needs a custom little helper trait.

This also fixes the annoying wart that FileDescription::{read,write} received two self pointers: a &self and a FileDescriptionRef.

The 2nd commit switches epoll_wait over to a strong ref, which is now a lot easier. That fixes #4065.

src/shims/files.rs Outdated Show resolved Hide resolved
@RalfJung RalfJung added this pull request to the merge queue Dec 28, 2024
Merged via the queue into rust-lang:master with commit a2465fa Dec 28, 2024
7 checks passed
@RalfJung RalfJung deleted the fd-ref-refactor branch December 28, 2024 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle epoll fd closed while blocking
1 participant