Implemented the From trait for converting mio socket types into std#1767
Implemented the From trait for converting mio socket types into std#1767Thomasdezeeuw merged 5 commits intotokio-rs:masterfrom
Conversation
socket types without using the unsafe keyword
Thomasdezeeuw
left a comment
There was a problem hiding this comment.
Two small suggestions, if you can apply those to all implementations this LGTM.
Could you also add From implementations for the Unix-only UDS types in src/net/uds?
- Return temporaries instead of bound variables. - Removed unnecessary documentation for impl of std types.
domain sockets as well
I added the trait implementation for |
src/net/tcp/listener.rs
Outdated
| // mio::net::TcpListener which ensures that we actually pass in a valid file | ||
| // descriptor/socket | ||
| unsafe { | ||
| #[cfg(any(unix, target_os = "hermit"))] |
There was a problem hiding this comment.
This currently fails to build on WASI. Can you try the following, to see if that fixes it? You might need to add use std::os::wasi::io::{FromRawFd, IntoRawFd}; to some files.
| #[cfg(any(unix, target_os = "hermit"))] | |
| #[cfg(any(unix, target_os = "hermit", target_os = "wasi"))] |
There was a problem hiding this comment.
Sure. With that addition the lib can be built for the target wasm32-wasi on my machine.
Edit: We still get failing CI tasks but they do not seem to be related to the changes made in this PR since the same tasks fail in other MR as well.
|
Thanks @tglane |
Implemented the following traits for conversion between the mio socket types and the std socket types:
From<mio::net::UdpSocket> for std::net::UdpSocket;From<mio::net::TcpListener> for std::net::TcpListener;From<mio::net::TcpStream> for std::net::TcpStream;This allows the conversion without using the unsafe keyword in the user code. Inside of the trait function we use the
unsafekeyword to access the raw underlying socket of the mic sockets. But since the mid socket types are in a well-defined state after construction, the use of unsafe here should be safe.Closes #1754