Skip to content

Commit

Permalink
Haiku: no IPv6 available; use SO_KEEPALIVE & FD_CLOEXEC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicah committed Apr 25, 2017
1 parent c541b64 commit a62cb92
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
36 changes: 35 additions & 1 deletion src/ext.rs
Expand Up @@ -624,7 +624,9 @@ impl<T: AsRawSocket> AsSock for T {
cfg_if! {
if #[cfg(any(target_os = "macos", target_os = "ios"))] {
use libc::TCP_KEEPALIVE as KEEPALIVE_OPTION;
} else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] {
} else if #[cfg(any(target_os = "openbsd",
target_os = "netbsd",
target_os = "haiku"))] {
use libc::SO_KEEPALIVE as KEEPALIVE_OPTION;
} else if #[cfg(unix)] {
use libc::TCP_KEEPIDLE as KEEPALIVE_OPTION;
Expand Down Expand Up @@ -962,14 +964,24 @@ impl UdpSocketExt for UdpSocket {
get_opt::<c_int>(self.as_sock(), IPPROTO_IP, IP_MULTICAST_TTL)
.map(|b| b as u32)
}
#[cfg(not(target_os = "haiku"))]
fn set_multicast_loop_v6(&self, multicast_loop_v6: bool) -> io::Result<()> {
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_MULTICAST_LOOP,
multicast_loop_v6 as c_int)
}
#[cfg(target_os = "haiku")]
fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "no ipv6"))
}
#[cfg(not(target_os = "haiku"))]
fn multicast_loop_v6(&self) -> io::Result<bool> {
get_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_MULTICAST_LOOP)
.map(int2bool)
}
#[cfg(target_os = "haiku")]
fn multicast_loop_v6(&self) -> io::Result<bool> {
return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "no ipv6"))
}

fn set_ttl(&self, ttl: u32) -> io::Result<()> {
set_opt(self.as_sock(), IPPROTO_IP, IP_TTL, ttl as c_int)
Expand All @@ -980,13 +992,23 @@ impl UdpSocketExt for UdpSocket {
.map(|b| b as u32)
}

#[cfg(not(target_os = "haiku"))]
fn set_only_v6(&self, only_v6: bool) -> io::Result<()> {
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_V6ONLY, only_v6 as c_int)
}
#[cfg(target_os = "haiku")]
fn set_only_v6(&self, _: bool) -> io::Result<()> {
return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "no ipv6"))
}

#[cfg(not(target_os = "haiku"))]
fn only_v6(&self) -> io::Result<bool> {
get_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_V6ONLY).map(int2bool)
}
#[cfg(target_os = "haiku")]
fn only_v6(&self) -> io::Result<bool> {
Ok(false)
}

fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr)
-> io::Result<()> {
Expand All @@ -997,6 +1019,7 @@ impl UdpSocketExt for UdpSocket {
set_opt(self.as_sock(), IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
}

#[cfg(not(target_os = "haiku"))]
fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32)
-> io::Result<()> {
let mreq = ipv6_mreq {
Expand All @@ -1006,6 +1029,11 @@ impl UdpSocketExt for UdpSocket {
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_ADD_MEMBERSHIP,
mreq)
}
#[cfg(target_os = "haiku")]
fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32)
-> io::Result<()> {
return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "no ipv6"))
}

fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr)
-> io::Result<()> {
Expand All @@ -1016,6 +1044,7 @@ impl UdpSocketExt for UdpSocket {
set_opt(self.as_sock(), IPPROTO_IP, IP_DROP_MEMBERSHIP, mreq)
}

#[cfg(not(target_os = "haiku"))]
fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32)
-> io::Result<()> {
let mreq = ipv6_mreq {
Expand All @@ -1025,6 +1054,11 @@ impl UdpSocketExt for UdpSocket {
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_DROP_MEMBERSHIP,
mreq)
}
#[cfg(target_os = "haiku")]
fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32)
-> io::Result<()> {
return Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "no ipv6"))
}

fn set_read_timeout_ms(&self, dur: Option<u32>) -> io::Result<()> {
set_opt(self.as_sock(), SOL_SOCKET, SO_RCVTIMEO,
Expand Down
8 changes: 4 additions & 4 deletions src/sys/unix/mod.rs
Expand Up @@ -14,7 +14,7 @@ use std::mem;
use std::net::{TcpListener, TcpStream, UdpSocket};
use std::os::unix::io::FromRawFd;
use libc::{self, c_int};
#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "solaris", target_os = "haiku")))]
use libc::{ioctl, FIOCLEX};

mod impls;
Expand All @@ -32,7 +32,7 @@ pub struct Socket {
}

impl Socket {
#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "solaris", target_os = "haiku")))]
pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {
unsafe {
let fd = try!(::cvt(libc::socket(family, ty, 0)));
Expand All @@ -41,9 +41,9 @@ impl Socket {
}
}

// ioctl(FIOCLEX) is not supported by Solaris/Illumos,
// ioctl(FIOCLEX) is not supported by Solaris/Illumos/Haiku,
// use fcntl(FD_CLOEXEC) instead
#[cfg(target_os = "solaris")]
#[cfg(any(target_os = "solaris", target_os = "haiku"))]
pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {
unsafe {
let fd = try!(::cvt(libc::socket(family, ty, 0)));
Expand Down

0 comments on commit a62cb92

Please sign in to comment.