Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for QNX Neutrino #382

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rustdoc-args = ["--cfg", "docsrs"]
features = ["all"]

[target."cfg(unix)".dependencies]
libc = "0.2.124"
libc = "0.2.139"

[target."cfg(windows)".dependencies]
winapi = { version = "0.3.9", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
Expand Down
20 changes: 16 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,19 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
pub struct TcpKeepalive {
#[cfg_attr(target_os = "openbsd", allow(dead_code))]
time: Option<Duration>,
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
#[cfg(not(any(
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "nto",
)))]
interval: Option<Duration>,
#[cfg(not(any(
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "windows"
target_os = "windows",
target_os = "nto",
)))]
retries: Option<u32>,
}
Expand All @@ -345,13 +351,19 @@ impl TcpKeepalive {
pub const fn new() -> TcpKeepalive {
TcpKeepalive {
time: None,
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
#[cfg(not(any(
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "nto",
)))]
interval: None,
#[cfg(not(any(
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "windows"
target_os = "windows",
target_os = "nto",
)))]
retries: None,
}
Expand Down
1 change: 1 addition & 0 deletions src/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ impl fmt::Debug for SockAddr {
target_os = "netbsd",
target_os = "openbsd",
target_os = "vxworks",
target_os = "nto",
))]
f.field("ss_len", &self.storage.ss_len);
f.field("ss_family", &self.storage.ss_family)
Expand Down
12 changes: 11 additions & 1 deletion src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use std::io::{self, Read, Write};
#[cfg(not(target_os = "redox"))]
use std::io::{IoSlice, IoSliceMut};
use std::mem::MaybeUninit;
use std::net::{self, Ipv4Addr, Ipv6Addr, Shutdown};
#[cfg(not(target_os = "nto"))]
use std::net::Ipv6Addr;
use std::net::{self, Ipv4Addr, Shutdown};
#[cfg(unix)]
use std::os::unix::io::{FromRawFd, IntoRawFd};
#[cfg(windows)]
Expand Down Expand Up @@ -1138,6 +1140,7 @@ impl Socket {
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "nto",
)))]
pub fn join_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1167,6 +1170,7 @@ impl Socket {
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "nto",
)))]
pub fn leave_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1198,6 +1202,7 @@ impl Socket {
target_os = "openbsd",
target_os = "redox",
target_os = "fuchsia",
target_os = "nto",
)))]
pub fn join_ssm_v4(
&self,
Expand Down Expand Up @@ -1232,6 +1237,7 @@ impl Socket {
target_os = "openbsd",
target_os = "redox",
target_os = "fuchsia",
target_os = "nto",
)))]
pub fn leave_ssm_v4(
&self,
Expand Down Expand Up @@ -1407,6 +1413,7 @@ impl Socket {
target_os = "redox",
target_os = "solaris",
target_os = "windows",
target_os = "nto",
)))]
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
let recv_tos = if recv_tos { 1 } else { 0 };
Expand Down Expand Up @@ -1435,6 +1442,7 @@ impl Socket {
target_os = "redox",
target_os = "solaris",
target_os = "windows",
target_os = "nto",
)))]
pub fn recv_tos(&self) -> io::Result<bool> {
unsafe {
Expand All @@ -1457,6 +1465,7 @@ impl Socket {
/// This function specifies a new multicast group for this socket to join.
/// The address must be a valid multicast address, and `interface` is the
/// index of the interface to join/leave (or 0 to indicate any interface).
#[cfg(not(target_os = "nto"))]
pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
let mreq = sys::Ipv6Mreq {
ipv6mr_multiaddr: sys::to_in6_addr(multiaddr),
Expand All @@ -1480,6 +1489,7 @@ impl Socket {
/// For more information about this option, see [`join_multicast_v6`].
///
/// [`join_multicast_v6`]: Socket::join_multicast_v6
#[cfg(not(target_os = "nto"))]
pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
let mreq = sys::Ipv6Mreq {
ipv6mr_multiaddr: sys::to_in6_addr(multiaddr),
Expand Down
37 changes: 28 additions & 9 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub(crate) use libc::{
#[cfg(not(target_os = "redox"))]
pub(crate) use libc::{MSG_TRUNC, SO_OOBINLINE};
// Used in `Socket`.
#[cfg(not(target_os = "nto"))]
pub(crate) use libc::ipv6_mreq as Ipv6Mreq;
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub(crate) use libc::IP_HDRINCL;
#[cfg(not(any(
Expand All @@ -85,6 +87,8 @@ pub(crate) use libc::IP_HDRINCL;
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "haiku",
target_os = "nto",
)))]
pub(crate) use libc::IP_RECVTOS;
#[cfg(not(any(
Expand All @@ -99,11 +103,11 @@ pub(crate) use libc::SO_LINGER;
#[cfg(target_vendor = "apple")]
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
pub(crate) use libc::{
ip_mreq as IpMreq, ipv6_mreq as Ipv6Mreq, linger, IPPROTO_IP, IPPROTO_IPV6,
IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY,
IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL,
IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF,
SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET,
SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF,
SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
};
#[cfg(not(any(
target_os = "dragonfly",
Expand All @@ -112,6 +116,7 @@ pub(crate) use libc::{
target_os = "openbsd",
target_os = "redox",
target_os = "fuchsia",
target_os = "nto",
)))]
pub(crate) use libc::{
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
Expand All @@ -124,6 +129,7 @@ pub(crate) use libc::{
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "nto",
target_vendor = "apple"
)))]
pub(crate) use libc::{IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP};
Expand Down Expand Up @@ -158,9 +164,14 @@ pub(crate) use libc::{TCP_KEEPCNT, TCP_KEEPINTVL};
// See this type in the Windows file.
pub(crate) type Bool = c_int;

#[cfg(target_vendor = "apple")]
#[cfg(any(target_vendor = "apple", target_os = "nto"))]
use libc::TCP_KEEPALIVE as KEEPALIVE_TIME;
#[cfg(not(any(target_vendor = "apple", target_os = "haiku", target_os = "openbsd")))]
#[cfg(not(any(
target_vendor = "apple",
target_os = "haiku",
target_os = "openbsd",
target_os = "nto",
)))]
use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;

/// Helper macro to execute a system call that returns an `io::Result`.
Expand Down Expand Up @@ -219,6 +230,7 @@ type IovLen = usize;
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "nto",
target_vendor = "apple",
))]
type IovLen = c_int;
Expand Down Expand Up @@ -903,7 +915,7 @@ pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {

#[allow(unused_variables)]
pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
if let Some(time) = keepalive.time {
let secs = into_secs(time);
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
Expand All @@ -930,10 +942,16 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
}
}

#[cfg(target_os = "nto")]
if let Some(time) = keepalive.time {
let secs = into_timeval(Some(time));
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
}

Ok(())
}

#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
fn into_secs(duration: Duration) -> c_int {
min(duration.as_secs(), c_int::max_value() as u64) as c_int
}
Expand Down Expand Up @@ -1028,6 +1046,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
target_os = "openbsd",
target_os = "redox",
target_os = "solaris",
target_os = "nto",
)))]
pub(crate) fn to_mreqn(
multiaddr: &Ipv4Addr,
Expand Down