From 95ce7ca98563cb31820ed9b68e31b0e573a28abc Mon Sep 17 00:00:00 2001 From: Evan Rittenhouse Date: Tue, 2 Jul 2024 17:05:27 -0500 Subject: [PATCH] Platform flags --- apps/src/recvfrom.rs | 5 +++-- dgram/src/lib.rs | 4 +++- dgram/src/syscalls.rs | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/src/recvfrom.rs b/apps/src/recvfrom.rs index b59310b84a..19c0e2c647 100644 --- a/apps/src/recvfrom.rs +++ b/apps/src/recvfrom.rs @@ -1,5 +1,6 @@ use dgram::RecvData; +#[cfg(target_os = "linux")] use std::io; /// For Linux, try to detect if GRO is available. If it is, the @@ -28,7 +29,7 @@ pub fn detect_gro(socket: &mio::net::UdpSocket) -> bool { } #[cfg(not(target_os = "linux"))] -pub fn detect_gro(socket: &mio::net::UdpSocket, _segment_size: usize) -> bool { +pub fn detect_gro(_socket: &mio::net::UdpSocket) -> bool { false } @@ -52,7 +53,7 @@ pub fn recv_from( } #[cfg(not(target_os = "linux"))] -fn recv_from( +pub fn recv_from( socket: &mio::net::UdpSocket, buf: &mut [u8], ) -> std::io::Result { match socket.recv_from(buf) { diff --git a/dgram/src/lib.rs b/dgram/src/lib.rs index 4f26d7a923..ad8dc3fb3a 100644 --- a/dgram/src/lib.rs +++ b/dgram/src/lib.rs @@ -1,10 +1,12 @@ pub mod socket_setup; +#[cfg(target_os = "linux")] pub mod sync; mod syscalls; #[cfg(feature = "async")] pub mod tokio; use std::net::SocketAddr; +#[cfg(target_os = "linux")] use std::time::Instant; use std::time::SystemTime; @@ -13,7 +15,6 @@ use libc::in_pktinfo; use libc::sockaddr_in; use libc::sockaddr_in6; use nix::sys::socket::ControlMessageOwned; -use nix::sys::socket::MsgFlags; /// Settings for handling control messages when sending data. #[cfg(target_os = "linux")] @@ -45,6 +46,7 @@ pub struct RecvMsgSettings<'c> { pub cmsg_space: &'c mut Vec, } +#[cfg(target_os = "linux")] impl<'c> RecvMsgSettings<'c> { // Convenience to avoid forcing a specific version of nix pub fn new(store_cmsgs: bool, cmsg_space: &'c mut Vec) -> Self { diff --git a/dgram/src/syscalls.rs b/dgram/src/syscalls.rs index ddba231676..ccc5e89c79 100644 --- a/dgram/src/syscalls.rs +++ b/dgram/src/syscalls.rs @@ -1,10 +1,9 @@ -use std::time::SystemTime; - #[cfg(target_os = "linux")] mod linux { pub(super) use super::super::linux_imports::*; pub(super) use std::os::fd::AsFd; pub(super) use std::time::Instant; + pub(super) use std::time::SystemTime; pub(crate) type SyscallResult = std::result::Result; @@ -17,6 +16,7 @@ mod linux { #[cfg(target_os = "linux")] use linux::*; +#[cfg(target_os = "linux")] fn raw_send_to( fd: &impl AsFd, send_buf: &[u8], cmsgs: &[ControlMessage], msg_flags: MsgFlags, client_addr: Option, @@ -27,7 +27,7 @@ fn raw_send_to( sendmsg( borrowed.as_raw_fd(), &iov, - &cmsgs, + cmsgs, msg_flags, client_addr.as_ref(), )