diff options
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/addr.rs | 25 | ||||
| -rw-r--r-- | src/libstd/net/ip.rs | 2 | ||||
| -rw-r--r-- | src/libstd/net/parser.rs | 2 | ||||
| -rw-r--r-- | src/libstd/net/tcp.rs | 20 |
4 files changed, 42 insertions, 7 deletions
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index a59d7f0263b..de6360cf020 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -901,7 +901,7 @@ impl ToSocketAddrs for str { type Iter = vec::IntoIter<SocketAddr>; fn to_socket_addrs(&self) -> io::Result<vec::IntoIter<SocketAddr>> { // try to parse as a regular SocketAddr first - if let Some(addr) = self.parse().ok() { + if let Ok(addr) = self.parse() { return Ok(vec![addr].into_iter()); } @@ -989,11 +989,26 @@ mod tests { // s has been moved into the tsa call } - // FIXME: figure out why this fails on openbsd and fix it #[test] - #[cfg(not(any(windows, target_os = "openbsd")))] - fn to_socket_addr_str_bad() { - assert!(tsa("1200::AB00:1234::2552:7777:1313:34300").is_err()); + fn bind_udp_socket_bad() { + // rust-lang/rust#53957: This is a regression test for a parsing problem + // discovered as part of issue rust-lang/rust#23076, where we were + // incorrectly parsing invalid input and then that would result in a + // successful `UdpSocket` binding when we would expect failure. + // + // At one time, this test was written as a call to `tsa` with + // INPUT_23076. However, that structure yields an unreliable test, + // because it ends up passing junk input to the DNS server, and some DNS + // servers will respond with `Ok` to such input, with the ip address of + // the DNS server itself. + // + // This form of the test is more robust: even when the DNS server + // returns its own address, it is still an error to bind a UDP socket to + // a non-local address, and so we still get an error here in that case. + + const INPUT_23076: &'static str = "1200::AB00:1234::2552:7777:1313:34300"; + + assert!(crate::net::UdpSocket::bind(INPUT_23076).is_err()) } #[test] diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 200b00b1195..edc28033c9b 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -651,7 +651,7 @@ impl Ipv4Addr { /// Returns [`true`] if this address is reserved by IANA for future use. [IETF RFC 1112] /// defines the block of reserved addresses as `240.0.0.0/4`. This range normally includes the - /// broadcast address `255.255.255.255`, but this implementation explicitely excludes it, since + /// broadcast address `255.255.255.255`, but this implementation explicitly excludes it, since /// it is obviously not reserved for future use. /// /// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112 diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index 868a7e261c4..3f38ee54710 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -206,7 +206,7 @@ impl<'a> Parser<'a> { } // read `::` if previous code parsed less than 8 groups - if !self.read_given_char(':').is_some() || !self.read_given_char(':').is_some() { + if self.read_given_char(':').is_none() || self.read_given_char(':').is_none() { return None; } diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 5023d692408..9ac54dd5f7a 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -577,6 +577,11 @@ impl Read for TcpStream { } #[inline] + fn is_read_vectored(&self) -> bool { + self.0.is_read_vectored() + } + + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() } @@ -591,6 +596,11 @@ impl Write for TcpStream { self.0.write_vectored(bufs) } + #[inline] + fn is_write_vectored(&self) -> bool { + self.0.is_write_vectored() + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } @@ -606,6 +616,11 @@ impl Read for &TcpStream { } #[inline] + fn is_read_vectored(&self) -> bool { + self.0.is_read_vectored() + } + + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() } @@ -620,6 +635,11 @@ impl Write for &TcpStream { self.0.write_vectored(bufs) } + #[inline] + fn is_write_vectored(&self) -> bool { + self.0.is_write_vectored() + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } |
