Allow registration of custom handles on Windows #504
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.
This commit intends to extend the functionality of mio on Windows to support
custom handles being registered with the internal IOCP object. This in turn
should unlock the ability to work with named pipes, filesystem changes, or any
other IOCP-enabled object on Windows. Named pipes are in particular quite
important as they're often a foundational IPC mechanism on Windows.
This support is provided by exporting two new types in a
windows
module. ARegistration
serves as the ability to register with the actual IOCP port in anEvented
implementation. Internally theRegistration
keeps track of what itwas last associated with to implement IOCP semantics. This may one day be
possible to make a zero-sized-type.
The second type,
Overlapped
, is exported as a contract that all overlapped I/Ooperations must be executed with this particular type. This ensures that after
an event is received from an IOCP object we know what to do with it. Essentially
this is just a
OVERLAPPED
with a function pointer after it.Along the way this exposes the
miow
crate as a public dependency ofmio
. TheCompletionStatus
andOverlapped
types inmiow
are exposed through theOverlapped
type that mio itself exports.I've implemented [bindings to named pipes][bindings] and I've also got a
proof-of-concept [process management library][tokio-process] using these
bindings. So far it seems that this support in mio is sufficient for building up
these applications, and it all appears to be working so far.
I personally see this as a much bigger committment on the mio side of things
than the Unix implementation. The
EventedFd
type on Unix is quite small andminimal, but the
Overlapped
andRegistration
types on Windows are justpieces of a larger puzzle when dealing with overlapped operations. Questions
about ownership of I/O objects arise along with the method of handling
completion status notifications. For now this is essentially binding mio to
stick to at least the same strategy for handling IOCP for the 0.6 series. A
major version bump of mio could perhaps change these semantics, but it may be
difficult to do so.
It seems, though, that the Windows semantics are unlikely to change much in the
near future. The overhead seems to have essentially reached its limit ("bolting
readiness on completion") and otherwise the ownership management seems
negligible.
Closes #252
Closes #320