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

Implement I/O-safe traits on types

Open notgull opened this issue 3 years ago • 5 comments

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

notgull avatar Aug 11 '22 20:08 notgull

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?

yoshuawuyts avatar Aug 17 '22 15:08 yoshuawuyts

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.

sunfishcode avatar Aug 17 '22 15:08 sunfishcode

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.

sunfishcode avatar Aug 23 '22 21:08 sunfishcode

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.

sunfishcode avatar Aug 26 '22 18:08 sunfishcode

What is the current status of this PR?

notgull avatar Sep 18 '22 18:09 notgull

@yoshuawuyts Is there anything I can do to move this PR forwards?

notgull avatar Nov 09 '22 17:11 notgull

Commented on a couple of minor issues. Happy to merge this with those fixed.

joshtriplett avatar Apr 30 '23 15:04 joshtriplett