From e1ae9c5f2aa5cc4e6c9abdf2c121c3fecc2cfcdb Mon Sep 17 00:00:00 2001 From: Evan Rittenhouse Date: Tue, 23 Apr 2024 23:40:03 -0500 Subject: [PATCH] Fix MacOS CI --- dgram/src/async_socket.rs | 6 +++--- dgram/src/syscalls.rs | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dgram/src/async_socket.rs b/dgram/src/async_socket.rs index 7eeafa1abf..f241a81576 100644 --- a/dgram/src/async_socket.rs +++ b/dgram/src/async_socket.rs @@ -1,8 +1,6 @@ use crate::syscalls::RecvData; -use std::io::ErrorKind; use std::io::Result; use std::net::SocketAddr; -use std::os::fd::AsRawFd; use std::time::Instant; use tokio::net::UdpSocket; @@ -12,6 +10,8 @@ mod linux_imports { pub(super) use crate::syscalls::send_msg; pub(super) use nix::sys::socket::MsgFlags; pub(super) use nix::sys::socket::SockaddrStorage; + pub(super) use std::io::ErrorKind; + pub(super) use std::os::fd::AsRawFd; pub(super) use tokio::io::Interest; } @@ -73,7 +73,7 @@ pub async fn recv_from( pub async fn send_to( socket: &tokio::net::UdpSocket, client_addr: SocketAddr, send_buf: &[u8], _segment_size: usize, _num_pkts: usize, _tx_time: Option, -) -> io::Result { +) -> Result { socket.send_to(send_buf, client_addr).await } diff --git a/dgram/src/syscalls.rs b/dgram/src/syscalls.rs index 89645a6f70..55ca1dae8e 100644 --- a/dgram/src/syscalls.rs +++ b/dgram/src/syscalls.rs @@ -1,10 +1,5 @@ -use std::io::IoSlice; -use std::io::IoSliceMut; -use std::io::Result; +use nix::sys::socket::ControlMessageOwned; use std::net::SocketAddr; -use std::net::SocketAddrV4; -use std::net::SocketAddrV6; -use std::os::fd::AsRawFd; use std::time::Instant; use std::time::SystemTime; @@ -15,11 +10,16 @@ mod linux_imports { pub(super) use nix::sys::socket::sendmsg; pub(super) use nix::sys::socket::AddressFamily; pub(super) use nix::sys::socket::ControlMessage; - pub(super) use nix::sys::socket::ControlMessageOwned; pub(super) use nix::sys::socket::MsgFlags; pub(super) use nix::sys::socket::SockaddrLike; pub(super) use nix::sys::socket::SockaddrStorage; pub(super) use smallvec::SmallVec; + pub(super) use std::io::IoSlice; + pub(super) use std::io::IoSliceMut; + pub(super) use std::io::Result; + pub(super) use std::net::SocketAddrV4; + pub(super) use std::net::SocketAddrV6; + pub(super) use std::os::fd::AsRawFd; } #[cfg(target_os = "linux")] @@ -27,6 +27,7 @@ use self::linux_imports::*; // An instant with the value of zero, since [`Instant`] is backed by a version // of timespec this allows to extract raw values from an [`Instant`] +#[cfg(target_os = "linux")] const INSTANT_ZERO: Instant = unsafe { std::mem::transmute(0u128) }; #[cfg(target_os = "linux")] @@ -94,6 +95,7 @@ impl RecvData { /// /// It is the caller's responsibility to create and clear the cmsg space. `nix` /// recommends that the space be created via the `cmsg_space!()` macro. +#[cfg(target_os = "linux")] pub fn recv_msg( fd: impl AsRawFd, read_buf: &mut [u8], cmsg_space: &mut Vec, msg_flags: Option, @@ -115,7 +117,7 @@ pub fn recv_msg( let address = match r.address { Some(a) => a, - _ => return Err(Errno::EINVAL.into()), + _ => return Err(Errno::EINVAL), }; let peer_addr = match address.family() { @@ -146,7 +148,7 @@ pub fn recv_msg( } } -#[cfg(test)] +#[cfg(all(test, target_os = "linux"))] mod tests { use nix::cmsg_space; use nix::sys::socket::sockopt::ReceiveTimestampns;