more gates
diff --git a/dgram/src/lib.rs b/dgram/src/lib.rs
index ad8dc3f..1800641 100644
--- a/dgram/src/lib.rs
+++ b/dgram/src/lib.rs
@@ -10,11 +10,30 @@
use std::time::Instant;
use std::time::SystemTime;
-use libc::in6_pktinfo;
-use libc::in_pktinfo;
-use libc::sockaddr_in;
-use libc::sockaddr_in6;
-use nix::sys::socket::ControlMessageOwned;
+#[cfg(unix)]
+mod unix {
+ use libc::in6_pktinfo;
+ use libc::in_pktinfo;
+ use libc::sockaddr_in;
+ use libc::sockaddr_in6;
+ pub(super) use nix::sys::socket::ControlMessageOwned;
+
+ #[derive(Debug)]
+ pub enum IpOrigDstAddr {
+ V4(sockaddr_in),
+ V6(sockaddr_in6),
+ }
+
+ #[cfg(unix)]
+ #[derive(Copy, Clone, Debug)]
+ pub enum IpPktInfo {
+ V4(in_pktinfo),
+ V6(in6_pktinfo),
+ }
+}
+
+#[cfg(unix)]
+pub use unix::{IpOrigDstAddr, IpPktInfo};
/// Settings for handling control messages when sending data.
#[cfg(target_os = "linux")]
@@ -79,8 +98,10 @@
///
/// This can be either an IPv4 or IPv6 address, depending on whether
/// `IPV4_ORIGDSTADDR` or `IPV6_ORIGDSTADDR` was received.
+ #[cfg(unix)]
pub original_addr: Option<IpOrigDstAddr>,
- cmsgs: Vec<ControlMessageOwned>,
+ #[cfg(unix)]
+ cmsgs: Vec<unix::ControlMessageOwned>,
}
impl RecvData {
@@ -93,7 +114,9 @@
metrics: None,
gro: None,
rx_time: None,
+ #[cfg(unix)]
original_addr: None,
+ #[cfg(unix)]
cmsgs: Vec::with_capacity(cmsg_space_len),
}
}
@@ -109,7 +132,8 @@
/// Returns the list of cmsgs which were returned from calling `recvmsg`. If
/// `recvmsg` was called with its [`RecvMsgCmsgSettings::store_cmsgs`]
/// field set to to `false`, this will return an empty slice.
- pub fn cmsgs(&self) -> &[ControlMessageOwned] {
+ #[cfg(unix)]
+ pub fn cmsgs(&self) -> &[unix::ControlMessageOwned] {
&self.cmsgs
}
}
@@ -124,18 +148,6 @@
pub udp_packets_dropped: u64,
}
-#[derive(Debug)]
-pub enum IpOrigDstAddr {
- V4(sockaddr_in),
- V6(sockaddr_in6),
-}
-
-#[derive(Copy, Clone, Debug)]
-pub enum IpPktInfo {
- V4(in_pktinfo),
- V6(in6_pktinfo),
-}
-
#[cfg(target_os = "linux")]
mod linux_imports {
pub(super) use crate::syscalls::recv_msg;
diff --git a/dgram/src/socket_setup.rs b/dgram/src/socket_setup.rs
index 6782223..e1a7656 100644
--- a/dgram/src/socket_setup.rs
+++ b/dgram/src/socket_setup.rs
@@ -1,9 +1,12 @@
-use std::io;
-use std::os::fd::AsFd;
-
#[cfg(target_os = "linux")]
use super::linux_imports::*;
+#[cfg(unix)]
+mod unix {
+ pub(super) use std::io;
+ pub(super) use std::os::fd::AsFd;
+}
+
/// Indicators of settings applied to a socket. These settings aren't "applied"
/// to a socket. Rather, the same (maximal) settings are always applied to a
/// socket, and this struct indicates which of those settings were successfully
@@ -31,7 +34,7 @@
/// which settings were successfully applied.
#[cfg(unix)]
pub fn apply_all_and_get_compatibility(
- socket: &impl AsFd, max_send_udp_payload_size: usize,
+ socket: &impl unix::AsFd, max_send_udp_payload_size: usize,
) -> Self {
let fd = socket.as_fd();
@@ -52,8 +55,8 @@
Ok(())
}
-#[cfg(not(target_os = "linux"))]
-pub fn set_gso_segment(_: &impl AsFd, _: usize) -> io::Result<()> {
+#[cfg(all(not(target_os = "linux"), unix))]
+pub fn set_gso_segment(_: &impl unix::AsFd, _: usize) -> unix::io::Result<()> {
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}
@@ -65,7 +68,8 @@
}
#[cfg(not(target_os = "linux"))]
-pub fn set_gro(_: &impl AsFd) -> io::Result<()> {
+#[cfg(all(not(target_os = "linux"), unix))]
+pub fn set_gro(_: &impl unix::AsFd) -> unix::io::Result<()> {
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}
@@ -76,8 +80,8 @@
Ok(())
}
-#[cfg(not(target_os = "linux"))]
-fn set_udp_rxq_ovfl(_: &impl AsFd) -> io::Result<()> {
+#[cfg(all(not(target_os = "linux"), unix))]
+fn set_udp_rxq_ovfl(_: &impl unix::AsFd) -> unix::io::Result<()> {
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}
@@ -93,8 +97,8 @@
Ok(())
}
-#[cfg(not(target_os = "linux"))]
-pub fn set_tx_time(_: &impl AsFd) -> io::Result<()> {
+#[cfg(all(not(target_os = "linux"), unix))]
+pub fn set_tx_time(_: &impl unix::AsFd) -> unix::io::Result<()> {
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}
@@ -105,7 +109,7 @@
Ok(())
}
-#[cfg(not(target_os = "linux"))]
-pub fn set_rx_time(_: &impl AsFd) -> io::Result<()> {
+#[cfg(all(not(target_os = "linux"), unix))]
+pub fn set_rx_time(_: &impl unix::AsFd) -> unix::io::Result<()> {
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}