]> git.lizzy.rs Git - rust.git/commitdiff
Fix comments and OSX build
authorSteven Fackler <sfackler@gmail.com>
Thu, 3 Mar 2016 06:05:14 +0000 (22:05 -0800)
committerSteven Fackler <sfackler@gmail.com>
Thu, 3 Mar 2016 06:05:14 +0000 (22:05 -0800)
src/libstd/net/tcp.rs
src/libstd/sys/common/net.rs

index 0073b8f119afa6b72770a1f8aa717daf537c7edd..f8e3b58bb3e9565f994faca1790966a9fb3e87b0 100644 (file)
@@ -1152,9 +1152,16 @@ fn set_nonblocking() {
         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),
+        }
     }
 }
index c8738fd1ba52475bb86ae8663012b936f95d4a55..d16380a96b29113b53e0d7ff827076bdbee815b9 100644 (file)
 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<T>(sock: &Socket, opt: c_int, val: c_int,
 }
 
 pub fn getsockopt<T: Copy>(sock: &Socket, opt: c_int,
-                       val: c_int) -> io::Result<T> { unsafe {
+                       val: c_int) -> io::Result<T> {
+    unsafe {
         let mut slot: T = mem::zeroed();
         let mut len = mem::size_of::<T>() as c::socklen_t;
         try!(cvt(c::getsockopt(*sock.as_inner(), opt, val,
@@ -532,7 +550,7 @@ pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32)
             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 @@ pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32)
             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<()> {