A NtCreateWaitCompletionPacket and NtAssociateWaitCompletionPacket realisation to poll CreateWaitableTimer and CreateEvent handles#1927
Conversation
…t to poll the Event based handles (experimental)
… a callback system was implemented. Added SourceEventHndl and SourceHndl. Added tokens.rs which generates mapped tokens.selector.rs: feeder was reimplemented to identify the source of event by mapped token. pipe, afd, waker and event are now working with internal token.
|
I decided to adapt some changes from closed source MIO crate (i.e from the organisation's private repository) to your OSS crate, but I had to change some things so as not to conflict with the interested parties and avoid making changes to the public API. I'd like to know what you think about these changes. And how likely is it that they will be accepted, or are those changes unsuitable? All changes are related to Windows only! Changes:
Now, a user provided token and internal token are separated. The former is used for identification of event outside of the crate. The latter is used for internal use only. The selector's event feeder receives the internal token and checks to which IO/event (i.e NamedPipe, Event, Waker etc. a facility) is it mapped. Then it routes a received data for parsing to this facility. A facility is holding the user provided token in Token Flow diagram |
|
I'm confused. Is this a new feature, or is it fixing a bug? If so, what is the bug? |
|
This is a new feature which allows to poll handles created by CreateWaitableTimerExW and CreateEventA which are not a file type. For example CreateWaitableTimerExW can be used with WaitMultipleObject call or IOCP via NtCreateWaitCompletionPacket and NtAssociateWaitCompletionPacket to IOCP instance. Another thing is a token for event identification. In order to introduce new feature, I decided to amend the token generation system and substitute it with a "mapped" internal token for internal events and resolve it to user defined token only when the event is emitted to the "poll" caller. (this is temporary solution) Because, I don't want to represent struct as "C" and count the offset using magic numbers instead (at least) using "offset_of()". There is a better solution for that, but cannot copy it from closed source mio fork. I need to re-implement it somehow. I don't have time for that. I need that feature to avoid calling |
…0432]: unresolved import `crate::sys::source_hndl`
…eimplemented callback for event handle. Ranges for tokens were increased by decreasing mask size.
|
In the recent commit I have fixed some issues with tests and errors. But I didn't format the code and will do it later if it will be approved. |
Hello,
Since this request doesn't break the API, I decided not to open an issue. Perhaps the implementation of this feature is not yet completely sensible, so I do not insist on its adoption.
I am working on project which uses Mio crate (from private repo but anyway). I was tidying up the "zoo" of IO subsystems of different OSes (with timers and stuff) and ran into the problem with this crate that it's impossible to poll the timer/events if handles are not files. In order to make it fully compatible with Windows, I developed some experimental code which adds a feature to 'poll' the timers and events.
A SourceEventHndl in source_hndl.rs is acting as a wrapper for any type which holds a 'handle' to object which was created by: CreateEvent or CreateWaitableTimer.
Windows-sys crate is missing some calls to NTDLL, so ffi.rs covers this. Tests pass successfully on Windows 10, but I don't have an opportunity to check if it runs on Windows 11 because, usually I am not writing a code for Windows. (And I don't have access to Win11 machine)
The code can be enabled using feature os-extended.
I tried my best not to touch the base code and integrate it as extension. For more details please check attached comments and test file win_event.rs and example windows_event.rs
Problems:
Example: