Skip to content

Commit 631fa2b

Browse files
committed
Fix comments and OSX build
1 parent 728d911 commit 631fa2b

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/libstd/net/tcp.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,16 @@ mod tests {
11521152
t!(listener.set_nonblocking(true));
11531153
t!(listener.set_nonblocking(false));
11541154

1155-
let stream = t!(TcpStream::connect(&("localhost", addr.port())));
1155+
let mut stream = t!(TcpStream::connect(&("localhost", addr.port())));
11561156

1157-
t!(stream.set_nonblocking(true));
11581157
t!(stream.set_nonblocking(false));
1158+
t!(stream.set_nonblocking(true));
1159+
1160+
let mut buf = [0];
1161+
match stream.read(&mut buf) {
1162+
Ok(_) => panic!("expected error"),
1163+
Err(ref e) if e.kind() == ErrorKind::WouldBlock => {}
1164+
Err(e) => panic!("unexpected error {}", e),
1165+
}
11591166
}
11601167
}

src/libstd/sys/common/net.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ use sys::net::netc as c;
2525
use sys_common::{AsInner, FromInner, IntoInner};
2626
use time::Duration;
2727

28+
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
29+
target_os = "ios", target_os = "macos",
30+
target_os = "openbsd"))]
31+
use sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP;
32+
#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd",
33+
target_os = "ios", target_os = "macos",
34+
target_os = "openbsd")))]
35+
use sys::net::netc::IPV6_ADD_MEMBERSHIP;
36+
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
37+
target_os = "ios", target_os = "macos",
38+
target_os = "openbsd"))]
39+
use sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
40+
#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd",
41+
target_os = "ios", target_os = "macos",
42+
target_os = "openbsd")))]
43+
use sys::net::netc::IPV6_DROP_MEMBERSHIP;
44+
2845
////////////////////////////////////////////////////////////////////////////////
2946
// sockaddr and misc bindings
3047
////////////////////////////////////////////////////////////////////////////////
@@ -40,7 +57,8 @@ pub fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int,
4057
}
4158

4259
pub fn getsockopt<T: Copy>(sock: &Socket, opt: c_int,
43-
val: c_int) -> io::Result<T> { unsafe {
60+
val: c_int) -> io::Result<T> {
61+
unsafe {
4462
let mut slot: T = mem::zeroed();
4563
let mut len = mem::size_of::<T>() as c::socklen_t;
4664
try!(cvt(c::getsockopt(*sock.as_inner(), opt, val,
@@ -532,7 +550,7 @@ impl UdpSocket {
532550
ipv6mr_multiaddr: *multiaddr.as_inner(),
533551
ipv6mr_interface: to_ipv6mr_interface(interface),
534552
};
535-
setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_ADD_MEMBERSHIP, mreq)
553+
setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq)
536554
}
537555

538556
pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr)
@@ -550,7 +568,7 @@ impl UdpSocket {
550568
ipv6mr_multiaddr: *multiaddr.as_inner(),
551569
ipv6mr_interface: to_ipv6mr_interface(interface),
552570
};
553-
setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_DROP_MEMBERSHIP, mreq)
571+
setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq)
554572
}
555573

556574
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {

0 commit comments

Comments
 (0)