diff options
| author | bors <bors@rust-lang.org> | 2021-08-20 11:00:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-20 11:00:55 +0000 |
| commit | 521734787ecf80ff12df7ca5998f7ec0b3b7b2c9 (patch) | |
| tree | 14d6353b5d2990f5572b35cfbf0c13422f0fd6f0 /library/std/src/net | |
| parent | 9ccf661694423895b02e513c69e6ad263b2f3d8e (diff) | |
| parent | b4dfa198bf4879bc159c7119bd4188ccd625f71d (diff) | |
| download | rust-521734787ecf80ff12df7ca5998f7ec0b3b7b2c9.tar.gz rust-521734787ecf80ff12df7ca5998f7ec0b3b7b2c9.zip | |
Auto merge of #87329 - sunfishcode:sunfishcode/io-safety, r=joshtriplett
I/O safety. Introduce `OwnedFd` and `BorrowedFd`, and the `AsFd` trait, and implementations of `AsFd`, `From<OwnedFd>` and `From<T> for OwnedFd` for relevant types, along with Windows counterparts for handles and sockets. Tracking issue: <https://github.com/rust-lang/rust/issues/87074> RFC: <https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md> Highlights: - The doc comments at the top of library/std/src/os/unix/io/mod.rs and library/std/src/os/windows/io/mod.rs - The new types and traits in library/std/src/os/unix/io/fd.rs and library/std/src/os/windows/io/handle.rs - The removal of the `RawHandle` struct the Windows impl, which had the same name as the `RawHandle` type alias, and its functionality is now folded into `Handle`. Managing five levels of wrapping (File wraps sys::fs::File wraps sys::fs::FileDesc wraps OwnedFd wraps RawFd, etc.) made for a fair amount of churn and verbose as/into/from sequences in some places. I've managed to simplify some of them, but I'm open to ideas here. r? `@joshtriplett`
Diffstat (limited to 'library/std/src/net')
| -rw-r--r-- | library/std/src/net/tcp.rs | 12 | ||||
| -rw-r--r-- | library/std/src/net/udp.rs | 6 | ||||
| -rw-r--r-- | library/std/src/net/udp/tests.rs | 3 |
3 files changed, 19 insertions, 2 deletions
diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index c8eb4811f7e..336891ec1eb 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -546,6 +546,12 @@ impl TcpStream { } } +// In addition to the `impl`s here, `TcpStream` also has `impl`s for +// `AsFd`/`From<OwnedFd>`/`Into<OwnedFd>` and +// `AsRawFd`/`IntoRawFd`/`FromRawFd`, on Unix and WASI, and +// `AsSocket`/`From<OwnedSocket>`/`Into<OwnedSocket>` and +// `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows. + #[stable(feature = "rust1", since = "1.0.0")] impl Read for TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { @@ -915,6 +921,12 @@ impl TcpListener { } } +// In addition to the `impl`s here, `TcpListener` also has `impl`s for +// `AsFd`/`From<OwnedFd>`/`Into<OwnedFd>` and +// `AsRawFd`/`IntoRawFd`/`FromRawFd`, on Unix and WASI, and +// `AsSocket`/`From<OwnedSocket>`/`Into<OwnedSocket>` and +// `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows. + #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Iterator for Incoming<'a> { type Item = io::Result<TcpStream>; diff --git a/library/std/src/net/udp.rs b/library/std/src/net/udp.rs index d2088a12b2c..871505843af 100644 --- a/library/std/src/net/udp.rs +++ b/library/std/src/net/udp.rs @@ -779,6 +779,12 @@ impl UdpSocket { } } +// In addition to the `impl`s here, `UdpSocket` also has `impl`s for +// `AsFd`/`From<OwnedFd>`/`Into<OwnedFd>` and +// `AsRawFd`/`IntoRawFd`/`FromRawFd`, on Unix and WASI, and +// `AsSocket`/`From<OwnedSocket>`/`Into<OwnedSocket>` and +// `AsRawSocket`/`IntoRawSocket`/`FromRawSocket` on Windows. + impl AsInner<net_imp::UdpSocket> for UdpSocket { fn as_inner(&self) -> &net_imp::UdpSocket { &self.0 diff --git a/library/std/src/net/udp/tests.rs b/library/std/src/net/udp/tests.rs index fbed3d32d45..a51113dd9e7 100644 --- a/library/std/src/net/udp/tests.rs +++ b/library/std/src/net/udp/tests.rs @@ -2,7 +2,6 @@ use crate::io::ErrorKind; use crate::net::test::{next_test_ip4, next_test_ip6}; use crate::net::*; use crate::sync::mpsc::channel; -use crate::sys_common::AsInner; use crate::thread; use crate::time::{Duration, Instant}; @@ -173,7 +172,7 @@ fn debug() { let socket_addr = next_test_ip4(); let udpsock = t!(UdpSocket::bind(&socket_addr)); - let udpsock_inner = udpsock.0.socket().as_inner(); + let udpsock_inner = udpsock.0.socket().as_raw(); let compare = format!("UdpSocket {{ addr: {:?}, {}: {:?} }}", socket_addr, name, udpsock_inner); assert_eq!(format!("{:?}", udpsock), compare); } |
