Skip to content

Commit 2579c7b

Browse files
committed
Add support for QNX Neutrino
1 parent 35ee2ff commit 2579c7b

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rustdoc-args = ["--cfg", "docsrs"]
3434
features = ["all"]
3535

3636
[target."cfg(unix)".dependencies]
37-
libc = "0.2.124"
37+
libc = "0.2.139"
3838

3939
[target.'cfg(windows)'.dependencies.windows-sys]
4040
version = "0.36"

Diff for: src/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,19 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
390390
pub struct TcpKeepalive {
391391
#[cfg_attr(target_os = "openbsd", allow(dead_code))]
392392
time: Option<Duration>,
393-
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
393+
#[cfg(not(any(
394+
target_os = "openbsd",
395+
target_os = "redox",
396+
target_os = "solaris",
397+
target_os = "nto",
398+
)))]
394399
interval: Option<Duration>,
395400
#[cfg(not(any(
396401
target_os = "openbsd",
397402
target_os = "redox",
398403
target_os = "solaris",
399-
target_os = "windows"
404+
target_os = "windows",
405+
target_os = "nto",
400406
)))]
401407
retries: Option<u32>,
402408
}
@@ -406,13 +412,19 @@ impl TcpKeepalive {
406412
pub const fn new() -> TcpKeepalive {
407413
TcpKeepalive {
408414
time: None,
409-
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
415+
#[cfg(not(any(
416+
target_os = "openbsd",
417+
target_os = "redox",
418+
target_os = "solaris",
419+
target_os = "nto",
420+
)))]
410421
interval: None,
411422
#[cfg(not(any(
412423
target_os = "openbsd",
413424
target_os = "redox",
414425
target_os = "solaris",
415-
target_os = "windows"
426+
target_os = "windows",
427+
target_os = "nto",
416428
)))]
417429
retries: None,
418430
}

Diff for: src/sockaddr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ impl fmt::Debug for SockAddr {
305305
target_os = "netbsd",
306306
target_os = "openbsd",
307307
target_os = "vxworks",
308+
target_os = "nto",
308309
))]
309310
f.field("ss_len", &self.storage.ss_len);
310311
f.field("ss_family", &self.storage.ss_family)

Diff for: src/socket.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use std::io::{self, Read, Write};
1111
#[cfg(not(target_os = "redox"))]
1212
use std::io::{IoSlice, IoSliceMut};
1313
use std::mem::MaybeUninit;
14-
use std::net::{self, Ipv4Addr, Ipv6Addr, Shutdown};
14+
#[cfg(not(target_os = "nto"))]
15+
use std::net::Ipv6Addr;
16+
use std::net::{self, Ipv4Addr, Shutdown};
1517
#[cfg(unix)]
1618
use std::os::unix::io::{FromRawFd, IntoRawFd};
1719
#[cfg(windows)]
@@ -1174,6 +1176,7 @@ impl Socket {
11741176
target_os = "openbsd",
11751177
target_os = "redox",
11761178
target_os = "solaris",
1179+
target_os = "nto",
11771180
)))]
11781181
pub fn join_multicast_v4_n(
11791182
&self,
@@ -1203,6 +1206,7 @@ impl Socket {
12031206
target_os = "openbsd",
12041207
target_os = "redox",
12051208
target_os = "solaris",
1209+
target_os = "nto",
12061210
)))]
12071211
pub fn leave_multicast_v4_n(
12081212
&self,
@@ -1234,6 +1238,7 @@ impl Socket {
12341238
target_os = "openbsd",
12351239
target_os = "redox",
12361240
target_os = "fuchsia",
1241+
target_os = "nto",
12371242
)))]
12381243
pub fn join_ssm_v4(
12391244
&self,
@@ -1268,6 +1273,7 @@ impl Socket {
12681273
target_os = "openbsd",
12691274
target_os = "redox",
12701275
target_os = "fuchsia",
1276+
target_os = "nto",
12711277
)))]
12721278
pub fn leave_ssm_v4(
12731279
&self,
@@ -1443,6 +1449,7 @@ impl Socket {
14431449
target_os = "redox",
14441450
target_os = "solaris",
14451451
target_os = "haiku",
1452+
target_os = "nto",
14461453
)))]
14471454
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
14481455
unsafe {
@@ -1469,6 +1476,7 @@ impl Socket {
14691476
target_os = "redox",
14701477
target_os = "solaris",
14711478
target_os = "haiku",
1479+
target_os = "nto",
14721480
)))]
14731481
pub fn recv_tos(&self) -> io::Result<bool> {
14741482
unsafe {
@@ -1491,6 +1499,7 @@ impl Socket {
14911499
/// This function specifies a new multicast group for this socket to join.
14921500
/// The address must be a valid multicast address, and `interface` is the
14931501
/// index of the interface to join/leave (or 0 to indicate any interface).
1502+
#[cfg(not(target_os = "nto"))]
14941503
pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
14951504
let mreq = sys::Ipv6Mreq {
14961505
ipv6mr_multiaddr: sys::to_in6_addr(multiaddr),
@@ -1514,6 +1523,7 @@ impl Socket {
15141523
/// For more information about this option, see [`join_multicast_v6`].
15151524
///
15161525
/// [`join_multicast_v6`]: Socket::join_multicast_v6
1526+
#[cfg(not(target_os = "nto"))]
15171527
pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
15181528
let mreq = sys::Ipv6Mreq {
15191529
ipv6mr_multiaddr: sys::to_in6_addr(multiaddr),

Diff for: src/sys/unix.rs

+30-12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub(crate) use libc::{
7676
#[cfg(not(target_os = "redox"))]
7777
pub(crate) use libc::{MSG_TRUNC, SO_OOBINLINE};
7878
// Used in `Socket`.
79+
#[cfg(not(target_os = "nto"))]
80+
pub(crate) use libc::ipv6_mreq as Ipv6Mreq;
7981
#[cfg(not(any(
8082
target_os = "dragonfly",
8183
target_os = "fuchsia",
@@ -98,6 +100,7 @@ pub(crate) use libc::IP_HDRINCL;
98100
target_os = "redox",
99101
target_os = "solaris",
100102
target_os = "haiku",
103+
target_os = "nto",
101104
)))]
102105
pub(crate) use libc::IP_RECVTOS;
103106
#[cfg(not(any(
@@ -112,11 +115,11 @@ pub(crate) use libc::SO_LINGER;
112115
#[cfg(target_vendor = "apple")]
113116
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
114117
pub(crate) use libc::{
115-
ip_mreq as IpMreq, ipv6_mreq as Ipv6Mreq, linger, IPPROTO_IP, IPPROTO_IPV6,
116-
IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY,
117-
IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL,
118-
IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF,
119-
SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
118+
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
119+
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
120+
IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET,
121+
SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF,
122+
SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
120123
};
121124
#[cfg(not(any(
122125
target_os = "dragonfly",
@@ -125,6 +128,7 @@ pub(crate) use libc::{
125128
target_os = "openbsd",
126129
target_os = "redox",
127130
target_os = "fuchsia",
131+
target_os = "nto",
128132
)))]
129133
pub(crate) use libc::{
130134
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
@@ -137,6 +141,7 @@ pub(crate) use libc::{
137141
target_os = "netbsd",
138142
target_os = "openbsd",
139143
target_os = "solaris",
144+
target_os = "nto",
140145
target_vendor = "apple"
141146
)))]
142147
pub(crate) use libc::{IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP};
@@ -171,9 +176,14 @@ pub(crate) use libc::{TCP_KEEPCNT, TCP_KEEPINTVL};
171176
// See this type in the Windows file.
172177
pub(crate) type Bool = c_int;
173178

174-
#[cfg(target_vendor = "apple")]
179+
#[cfg(any(target_vendor = "apple", target_os = "nto"))]
175180
use libc::TCP_KEEPALIVE as KEEPALIVE_TIME;
176-
#[cfg(not(any(target_vendor = "apple", target_os = "haiku", target_os = "openbsd")))]
181+
#[cfg(not(any(
182+
target_vendor = "apple",
183+
target_os = "haiku",
184+
target_os = "openbsd",
185+
target_os = "nto",
186+
)))]
177187
use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;
178188

179189
/// Helper macro to execute a system call that returns an `io::Result`.
@@ -236,6 +246,7 @@ type IovLen = usize;
236246
target_os = "netbsd",
237247
target_os = "openbsd",
238248
target_os = "solaris",
249+
target_os = "nto",
239250
target_vendor = "apple",
240251
))]
241252
type IovLen = c_int;
@@ -902,7 +913,7 @@ pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
902913

903914
#[allow(unused_variables)]
904915
pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
905-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
916+
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
906917
if let Some(time) = keepalive.time {
907918
let secs = into_secs(time);
908919
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
@@ -929,10 +940,16 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
929940
}
930941
}
931942

943+
#[cfg(target_os = "nto")]
944+
if let Some(time) = keepalive.time {
945+
let secs = into_timeval(Some(time));
946+
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
947+
}
948+
932949
Ok(())
933950
}
934951

935-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
952+
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
936953
fn into_secs(duration: Duration) -> c_int {
937954
min(duration.as_secs(), c_int::MAX as u64) as c_int
938955
}
@@ -1032,6 +1049,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
10321049
target_os = "openbsd",
10331050
target_os = "redox",
10341051
target_os = "solaris",
1052+
target_os = "nto",
10351053
)))]
10361054
pub(crate) const fn to_mreqn(
10371055
multiaddr: &Ipv4Addr,
@@ -1071,7 +1089,7 @@ impl crate::Socket {
10711089
target_os = "illumos",
10721090
target_os = "linux",
10731091
target_os = "netbsd",
1074-
target_os = "openbsd"
1092+
target_os = "openbsd",
10751093
)
10761094
))]
10771095
#[cfg_attr(
@@ -1086,7 +1104,7 @@ impl crate::Socket {
10861104
target_os = "illumos",
10871105
target_os = "linux",
10881106
target_os = "netbsd",
1089-
target_os = "openbsd"
1107+
target_os = "openbsd",
10901108
)
10911109
)))
10921110
)]
@@ -1102,7 +1120,7 @@ impl crate::Socket {
11021120
target_os = "illumos",
11031121
target_os = "linux",
11041122
target_os = "netbsd",
1105-
target_os = "openbsd"
1123+
target_os = "openbsd",
11061124
))]
11071125
pub(crate) fn _accept4(&self, flags: c_int) -> io::Result<(crate::Socket, SockAddr)> {
11081126
// Safety: `accept4` initialises the `SockAddr` for us.

0 commit comments

Comments
 (0)