async-std
async-std copied to clipboard
Implement I/O-safe traits on types
This PR adds a new feature, io_safety, which requires Rust 1.63 or higher. This trait implements the AsFd/AsHandle/AsSocket family of functions on async-std's types. In addition, several types also implement From<OwnedFd/OwnedHandle/OwnedSocket> and Into<OwnedFd/OwnedHandle/OwnedSocket>.
See also: sunfishcode/io-lifetimes#38
Tagging in @sunfishcode who likely has thoughts on how we should approach this.
edit: I believe file and stdio types may actually be unsound to implement these traits on on windows?
edit: I believe file and stdio types may actually be unsound to implement these traits on on windows?
Are you referring to the OVERLAPPED issue in Windows? It's my understanding that that's now fixed.
This change looks good to me. Overall, the intention for From<OwnedFd> and From<T> for OwnedFd impls is to mirror existing FromRawFd and IntoRawFd impls. In practice, the way FromRawFd and IntoRawFd are used, users assume they have ownership-transfer semantics, so if there any issues with soundness with the new traits, they'd likely already present with the existing traits.
Also, it's currently the case that async-std doesn't currently call ReadFile or NtReadFile itself; it currently uses std::fs::File::read from within spawn_blocking, so async-std wouldn't be doing anything that std itself isn't already doing.
What is the current status of this PR?
@yoshuawuyts Is there anything I can do to move this PR forwards?
Commented on a couple of minor issues. Happy to merge this with those fixed.