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 to master branch #380

Merged
merged 1 commit into from
Jan 16, 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 @@ -34,7 +34,7 @@ rustdoc-args = ["--cfg", "docsrs"]
features = ["all"]

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

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.36"
Expand Down
20 changes: 16 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,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 @@ -406,13 +412,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 @@ -305,6 +305,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 @@ -1174,6 +1176,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 @@ -1203,6 +1206,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 @@ -1234,6 +1238,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 @@ -1268,6 +1273,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 @@ -1443,6 +1449,7 @@ impl Socket {
target_os = "redox",
target_os = "solaris",
target_os = "haiku",
target_os = "nto",
)))]
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
unsafe {
Expand All @@ -1469,6 +1476,7 @@ impl Socket {
target_os = "redox",
target_os = "solaris",
target_os = "haiku",
target_os = "nto",
)))]
pub fn recv_tos(&self) -> io::Result<bool> {
unsafe {
Expand All @@ -1491,6 +1499,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 @@ -1514,6 +1523,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
42 changes: 30 additions & 12 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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(not(any(
target_os = "dragonfly",
target_os = "fuchsia",
Expand All @@ -98,6 +100,7 @@ pub(crate) use libc::IP_HDRINCL;
target_os = "redox",
target_os = "solaris",
target_os = "haiku",
target_os = "nto",
)))]
pub(crate) use libc::IP_RECVTOS;
#[cfg(not(any(
Expand All @@ -112,11 +115,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 @@ -125,6 +128,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 @@ -137,6 +141,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 @@ -171,9 +176,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 @@ -236,6 +246,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 @@ -902,7 +913,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 @@ -929,10 +940,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 as u64) as c_int
}
Expand Down Expand Up @@ -1032,6 +1049,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) const fn to_mreqn(
multiaddr: &Ipv4Addr,
Expand Down Expand Up @@ -1071,7 +1089,7 @@ impl crate::Socket {
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
)
))]
#[cfg_attr(
Expand All @@ -1086,7 +1104,7 @@ impl crate::Socket {
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
)
)))
)]
Expand All @@ -1102,7 +1120,7 @@ impl crate::Socket {
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"
target_os = "openbsd",
))]
pub(crate) fn _accept4(&self, flags: c_int) -> io::Result<(crate::Socket, SockAddr)> {
// Safety: `accept4` initialises the `SockAddr` for us.
Expand Down