\Device\Afd, or, the Deal with the Devil that makes async Rust work on Windows
notgull.github.io
notgull.github.io
> To make a long story that I don’t fully understand short, you need to have buffers that are pinned in memory and aren’t touched as long as the operation is in progress.
I don't understand why this is so confusing.
> I doubt that Microsoft is really rushing to make it so that you can’t run Javascript on Windows anymore.
Nah, but don't be surprised if suddenly a bunch of apps receive compatibility shims.
Pinning a buffer is easy. Dealing with ownership ramifications in all situations is confusing.
I found it odd that even the examples for low-level C APIs were presented through Rust wrappers.
"the overarching idea is that IOCP doesn’t gel well with not only the Future model, but also with Rust’s borrow checker as a whole" comes pretty close, though, but it's still lacking the insight that it's an issue in Rust's language design and not in Windows.
Also, I've heard a lot of praise about Microsoft's networking integration which made things like mounting network drives possible and reliable as early as Windows 2000. But of course, if you refuse to use the recommended APIs, you'll suffer for it.
I wonder if the author would describe it in similar detail, if they open a Linux device like /dev/video0 and send a V4L syscall to it. Because that's the equivalent to using the Afd device.
That said, I enjoyed their word choices and writing style.
Yup, you nailed it!
I did spend about 20 minutes looking into this, it seems that there's an (admittedly undocumented) IOCTL which is in the Winsock headers (MSWsock.h) called SIO_EXT_POLL which seems to just use the poll device IO control code and so they could probably do this without messing with low-level AFD weirdness.
That said you'd think with Microsoft going all in on Rust, last I heard at least, that they could find a way to re-implement this code correctly. Hell, if they at least documented the IOCTL they could probably get co-pilot to do it for them ;)
Precisely. As somebody with extensive experience porting cross-platform applications to run on Windows, it smells more to me like "everybody involved in this is actually quite ignorant about Windows," instead of (what I am assuming is the intended) "look at this crazy shit we had to do because Windows sucks."
Perl is a temple. You construct some ritualistic temple of a project, leave it be for years and will stand happily without any issues. Come back many months later, add a single comment; total Indiana Jones scenario.
TCL is voodoo, it does stuff that shouldn't work but does awesomely. How it does it is just voodoo.
Ruby is just magic. You create a thing, change one thing and the next thing you know you've suddenly got two features for the price of one.
PHP is a sheep.
However, every *nix / macOS person writes their epoll code, then finds out that it Doesn't Work That Way on Windows, so this gives them back their epoll-like API.