From 631fa2b8c059ecf22b69941d700d9c9fce0ed47f Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Wed, 2 Mar 2016 22:05:14 -0800 Subject: [PATCH] Fix comments and OSX build --- src/libstd/net/tcp.rs | 11 +++++++++-- src/libstd/sys/common/net.rs | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 0073b8f119a..f8e3b58bb3e 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -1152,9 +1152,16 @@ mod tests { t!(listener.set_nonblocking(true)); t!(listener.set_nonblocking(false)); - let stream = t!(TcpStream::connect(&("localhost", addr.port()))); + let mut stream = t!(TcpStream::connect(&("localhost", addr.port()))); - t!(stream.set_nonblocking(true)); t!(stream.set_nonblocking(false)); + t!(stream.set_nonblocking(true)); + + let mut buf = [0]; + match stream.read(&mut buf) { + Ok(_) => panic!("expected error"), + Err(ref e) if e.kind() == ErrorKind::WouldBlock => {} + Err(e) => panic!("unexpected error {}", e), + } } } diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index c8738fd1ba5..d16380a96b2 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -25,6 +25,23 @@ use sys::net::netc as c; use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; +#[cfg(any(target_os = "dragonfly", target_os = "freebsd", + target_os = "ios", target_os = "macos", + target_os = "openbsd"))] +use sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; +#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", + target_os = "ios", target_os = "macos", + target_os = "openbsd")))] +use sys::net::netc::IPV6_ADD_MEMBERSHIP; +#[cfg(any(target_os = "dragonfly", target_os = "freebsd", + target_os = "ios", target_os = "macos", + target_os = "openbsd"))] +use sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; +#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", + target_os = "ios", target_os = "macos", + target_os = "openbsd")))] +use sys::net::netc::IPV6_DROP_MEMBERSHIP; + //////////////////////////////////////////////////////////////////////////////// // sockaddr and misc bindings //////////////////////////////////////////////////////////////////////////////// @@ -40,7 +57,8 @@ pub fn setsockopt(sock: &Socket, opt: c_int, val: c_int, } pub fn getsockopt(sock: &Socket, opt: c_int, - val: c_int) -> io::Result { unsafe { + val: c_int) -> io::Result { + unsafe { let mut slot: T = mem::zeroed(); let mut len = mem::size_of::() as c::socklen_t; try!(cvt(c::getsockopt(*sock.as_inner(), opt, val, @@ -532,7 +550,7 @@ impl UdpSocket { ipv6mr_multiaddr: *multiaddr.as_inner(), ipv6mr_interface: to_ipv6mr_interface(interface), }; - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_ADD_MEMBERSHIP, mreq) + setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) } pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) @@ -550,7 +568,7 @@ impl UdpSocket { ipv6mr_multiaddr: *multiaddr.as_inner(), ipv6mr_interface: to_ipv6mr_interface(interface), }; - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_DROP_MEMBERSHIP, mreq) + setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {