Skip to content

Commit 3fff5c1

Browse files
flba-ebThomasdezeeuw
authored andcommitted
Add support for QNX Neutrino
Backport of commit 5b68514.
1 parent ff79dee commit 3fff5c1

File tree

5 files changed

+57
-15
lines changed

5 files changed

+57
-15
lines changed

Diff for: Cargo.toml

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

3535
[target."cfg(unix)".dependencies]
36-
libc = "0.2.124"
36+
libc = "0.2.139"
3737

3838
[target."cfg(windows)".dependencies]
3939
winapi = { version = "0.3.9", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }

Diff for: src/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,19 @@ impl<'a> DerefMut for MaybeUninitSlice<'a> {
329329
pub struct TcpKeepalive {
330330
#[cfg_attr(target_os = "openbsd", allow(dead_code))]
331331
time: Option<Duration>,
332-
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
332+
#[cfg(not(any(
333+
target_os = "openbsd",
334+
target_os = "redox",
335+
target_os = "solaris",
336+
target_os = "nto",
337+
)))]
333338
interval: Option<Duration>,
334339
#[cfg(not(any(
335340
target_os = "openbsd",
336341
target_os = "redox",
337342
target_os = "solaris",
338-
target_os = "windows"
343+
target_os = "windows",
344+
target_os = "nto",
339345
)))]
340346
retries: Option<u32>,
341347
}
@@ -345,13 +351,19 @@ impl TcpKeepalive {
345351
pub const fn new() -> TcpKeepalive {
346352
TcpKeepalive {
347353
time: None,
348-
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "solaris")))]
354+
#[cfg(not(any(
355+
target_os = "openbsd",
356+
target_os = "redox",
357+
target_os = "solaris",
358+
target_os = "nto",
359+
)))]
349360
interval: None,
350361
#[cfg(not(any(
351362
target_os = "openbsd",
352363
target_os = "redox",
353364
target_os = "solaris",
354-
target_os = "windows"
365+
target_os = "windows",
366+
target_os = "nto",
355367
)))]
356368
retries: None,
357369
}

Diff for: src/sockaddr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl fmt::Debug for SockAddr {
302302
target_os = "netbsd",
303303
target_os = "openbsd",
304304
target_os = "vxworks",
305+
target_os = "nto",
305306
))]
306307
f.field("ss_len", &self.storage.ss_len);
307308
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)]
@@ -1138,6 +1140,7 @@ impl Socket {
11381140
target_os = "openbsd",
11391141
target_os = "redox",
11401142
target_os = "solaris",
1143+
target_os = "nto",
11411144
)))]
11421145
pub fn join_multicast_v4_n(
11431146
&self,
@@ -1167,6 +1170,7 @@ impl Socket {
11671170
target_os = "openbsd",
11681171
target_os = "redox",
11691172
target_os = "solaris",
1173+
target_os = "nto",
11701174
)))]
11711175
pub fn leave_multicast_v4_n(
11721176
&self,
@@ -1198,6 +1202,7 @@ impl Socket {
11981202
target_os = "openbsd",
11991203
target_os = "redox",
12001204
target_os = "fuchsia",
1205+
target_os = "nto",
12011206
)))]
12021207
pub fn join_ssm_v4(
12031208
&self,
@@ -1232,6 +1237,7 @@ impl Socket {
12321237
target_os = "openbsd",
12331238
target_os = "redox",
12341239
target_os = "fuchsia",
1240+
target_os = "nto",
12351241
)))]
12361242
pub fn leave_ssm_v4(
12371243
&self,
@@ -1407,6 +1413,7 @@ impl Socket {
14071413
target_os = "redox",
14081414
target_os = "solaris",
14091415
target_os = "windows",
1416+
target_os = "nto",
14101417
)))]
14111418
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
14121419
let recv_tos = if recv_tos { 1 } else { 0 };
@@ -1435,6 +1442,7 @@ impl Socket {
14351442
target_os = "redox",
14361443
target_os = "solaris",
14371444
target_os = "windows",
1445+
target_os = "nto",
14381446
)))]
14391447
pub fn recv_tos(&self) -> io::Result<bool> {
14401448
unsafe {
@@ -1457,6 +1465,7 @@ impl Socket {
14571465
/// This function specifies a new multicast group for this socket to join.
14581466
/// The address must be a valid multicast address, and `interface` is the
14591467
/// index of the interface to join/leave (or 0 to indicate any interface).
1468+
#[cfg(not(target_os = "nto"))]
14601469
pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
14611470
let mreq = sys::Ipv6Mreq {
14621471
ipv6mr_multiaddr: sys::to_in6_addr(multiaddr),
@@ -1480,6 +1489,7 @@ impl Socket {
14801489
/// For more information about this option, see [`join_multicast_v6`].
14811490
///
14821491
/// [`join_multicast_v6`]: Socket::join_multicast_v6
1492+
#[cfg(not(target_os = "nto"))]
14831493
pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
14841494
let mreq = sys::Ipv6Mreq {
14851495
ipv6mr_multiaddr: sys::to_in6_addr(multiaddr),

Diff for: src/sys/unix.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ pub(crate) use libc::{
7575
#[cfg(not(target_os = "redox"))]
7676
pub(crate) use libc::{MSG_TRUNC, SO_OOBINLINE};
7777
// Used in `Socket`.
78+
#[cfg(not(target_os = "nto"))]
79+
pub(crate) use libc::ipv6_mreq as Ipv6Mreq;
7880
#[cfg(all(feature = "all", not(target_os = "redox")))]
7981
pub(crate) use libc::IP_HDRINCL;
8082
#[cfg(not(any(
@@ -85,6 +87,8 @@ pub(crate) use libc::IP_HDRINCL;
8587
target_os = "openbsd",
8688
target_os = "redox",
8789
target_os = "solaris",
90+
target_os = "haiku",
91+
target_os = "nto",
8892
)))]
8993
pub(crate) use libc::IP_RECVTOS;
9094
#[cfg(not(any(
@@ -99,11 +103,11 @@ pub(crate) use libc::SO_LINGER;
99103
#[cfg(target_vendor = "apple")]
100104
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
101105
pub(crate) use libc::{
102-
ip_mreq as IpMreq, ipv6_mreq as Ipv6Mreq, linger, IPPROTO_IP, IPPROTO_IPV6,
103-
IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY,
104-
IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL,
105-
IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF,
106-
SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF, SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
106+
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
107+
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
108+
IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, MSG_OOB, MSG_PEEK, SOL_SOCKET,
109+
SO_BROADCAST, SO_ERROR, SO_KEEPALIVE, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF,
110+
SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
107111
};
108112
#[cfg(not(any(
109113
target_os = "dragonfly",
@@ -112,6 +116,7 @@ pub(crate) use libc::{
112116
target_os = "openbsd",
113117
target_os = "redox",
114118
target_os = "fuchsia",
119+
target_os = "nto",
115120
)))]
116121
pub(crate) use libc::{
117122
ip_mreq_source as IpMreqSource, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
@@ -124,6 +129,7 @@ pub(crate) use libc::{
124129
target_os = "netbsd",
125130
target_os = "openbsd",
126131
target_os = "solaris",
132+
target_os = "nto",
127133
target_vendor = "apple"
128134
)))]
129135
pub(crate) use libc::{IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP};
@@ -158,9 +164,14 @@ pub(crate) use libc::{TCP_KEEPCNT, TCP_KEEPINTVL};
158164
// See this type in the Windows file.
159165
pub(crate) type Bool = c_int;
160166

161-
#[cfg(target_vendor = "apple")]
167+
#[cfg(any(target_vendor = "apple", target_os = "nto"))]
162168
use libc::TCP_KEEPALIVE as KEEPALIVE_TIME;
163-
#[cfg(not(any(target_vendor = "apple", target_os = "haiku", target_os = "openbsd")))]
169+
#[cfg(not(any(
170+
target_vendor = "apple",
171+
target_os = "haiku",
172+
target_os = "openbsd",
173+
target_os = "nto",
174+
)))]
164175
use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;
165176

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

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

945+
#[cfg(target_os = "nto")]
946+
if let Some(time) = keepalive.time {
947+
let secs = into_timeval(Some(time));
948+
unsafe { setsockopt(fd, libc::IPPROTO_TCP, KEEPALIVE_TIME, secs)? }
949+
}
950+
933951
Ok(())
934952
}
935953

936-
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
954+
#[cfg(not(any(target_os = "haiku", target_os = "openbsd", target_os = "nto")))]
937955
fn into_secs(duration: Duration) -> c_int {
938956
min(duration.as_secs(), c_int::max_value() as u64) as c_int
939957
}
@@ -1028,6 +1046,7 @@ pub(crate) fn from_in6_addr(addr: in6_addr) -> Ipv6Addr {
10281046
target_os = "openbsd",
10291047
target_os = "redox",
10301048
target_os = "solaris",
1049+
target_os = "nto",
10311050
)))]
10321051
pub(crate) fn to_mreqn(
10331052
multiaddr: &Ipv4Addr,

0 commit comments

Comments
 (0)