FD handling: avoid unnecessary dynamic downcasts #4114
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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>
whereT
indicates the type of the FD. We also haveDynFileDescriptionRef
for when the underlying type is not statically known. What makes this tricky is that we want to also have anFdId
available via the reference. We can useCoercePointee
to makeRc<(FdId, T)>
a dyn-compatible pointer type that can be the receiver ofread
/write
/close
. However, that's still not quite enough since we also want dynamic downcasting, and that is only possible withRc<dyn Any>
, so the usual "makeAny
a supertrait" does not work... we needFdIdWith<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 twoself
pointers: a&self
and aFileDescriptionRef
.The 2nd commit switches
epoll_wait
over to a strong ref, which is now a lot easier. That fixes #4065.