async-io icon indicating copy to clipboard operation
async-io copied to clipboard

Support for Handles on Windows

Open yoshuawuyts opened this issue 5 years ago • 7 comments

Windows has two kinds file descriptors: Handle and Socket. It seems smol::Async currently only support Socket but not yet Handle, which is needed to abstract over APIs such as named pipes. What is the plan for Handle-based APIs in smol?

yoshuawuyts avatar Apr 24 '20 23:04 yoshuawuyts

Similar to fds on UNIX this has the problem that not all Handles are waitable from what I understand, so that would have to be documented carefully. For all others, WaitForMultipleObjects() and friends would work.

IMHO this would be useful to have.

sdroege avatar Apr 25 '20 08:04 sdroege

To add some more information here, this is not just named pipes but also for example: waitable timers (basically Windows' timerfd equivalent), event objects, semaphores, threads/processes, mutexes and probably various other things I forgot.

sdroege avatar Apr 25 '20 08:04 sdroege

wepoll only seems to support SOCKET unfortunately, so might not be a good choice going forward unless it gets support for HANDLE.

sdroege avatar Apr 25 '20 18:04 sdroege

I think we could eventually add support for RawHandle through IOCP... but it's not at the top of my priority list, tbh.

ghost avatar Apr 25 '20 18:04 ghost

Makes sense and it's would only require internal changes anyway, not API-wise :)

sdroege avatar Apr 25 '20 19:04 sdroege

To add some more information here, this is not just named pipes but also for example: waitable timers (basically Windows' timerfd equivalent), event objects, semaphores, threads/processes, mutexes and probably various other things I forgot.

This isn't really a deal-breaker, but I was looking to play with reading Physical Disks using OVERLAPPED_IO. Not anything (that) useful, just something for-fun that I could use to help learn how async-io works.

Unfortunately, because there's no support for Handles, I can't actually open a Physical Disk to pass to Async to take care of "all the stuff that I don't feel like writing myself" :P.

cr1901 avatar Jan 12 '24 17:01 cr1901

Usage as you describe is currently blocked on https://github.com/smol-rs/polling/issues/97. But, waitable handles like processes can be used in https://github.com/smol-rs/async-io/pull/152

notgull avatar Jan 12 '24 18:01 notgull