Skip to content

Commit

Permalink
Fix other platform builds, pt. 2: The Sequel
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Apr 26, 2024
1 parent 60df557 commit 38aa4c5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ COPY apps/ ./apps/
COPY octets/ ./octets/
COPY qlog/ ./qlog/
COPY quiche/ ./quiche/
COPY dgram ./dgram/

RUN apt-get update && apt-get install -y cmake && rm -rf /var/lib/apt/lists/*

Expand Down
5 changes: 2 additions & 3 deletions dgram/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct GsoSettings {
mod linux_imports {
pub(super) use crate::syscalls::recv_msg;
pub(super) use crate::syscalls::send_msg;
pub(super) use crate::GsoSettings;
pub(super) use nix::errno::Errno;
pub(super) use nix::sys::socket::getsockopt;
pub(super) use nix::sys::socket::recvmsg;
Expand All @@ -25,6 +26,7 @@ mod linux_imports {
pub(super) use nix::sys::socket::sockopt::UdpGsoSegment;
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::SetSockOpt;
pub(super) use nix::sys::socket::SockaddrLike;
Expand All @@ -35,9 +37,6 @@ mod linux_imports {
pub(super) use std::net::SocketAddrV4;
pub(super) use std::net::SocketAddrV6;
pub(super) use std::os::fd::AsRawFd;

#[cfg(feature = "async")]
pub(super) use crate::async_imports::*;
}

#[cfg(feature = "async")]
Expand Down
12 changes: 6 additions & 6 deletions dgram/src/socket_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn set_gso_segment(sock: &impl AsFd, segment: usize) -> io::Result<()> {

#[cfg(not(target_os = "linux"))]
pub fn set_gso_segment(_: &impl AsFd, _: usize) -> io::Result<()> {
Err("unsupported").into_io()
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}

#[cfg(target_os = "linux")]
Expand All @@ -66,7 +66,7 @@ pub fn set_gro(sock: &impl AsFd) -> io::Result<()> {

#[cfg(not(target_os = "linux"))]
pub fn set_gro(_: &impl AsFd) -> io::Result<()> {
Err("unsupported").into_io()
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}

#[cfg(target_os = "linux")]
Expand All @@ -77,8 +77,8 @@ fn set_udp_rxq_ovfl(sock: &impl AsFd) -> io::Result<()> {
}

#[cfg(not(target_os = "linux"))]
fn set_udp_rxq_ovfl<S>(_: &impl AsFd) -> io::Result<()> {
Err("unsupported").into_io()
fn set_udp_rxq_ovfl(_: &impl AsFd) -> io::Result<()> {
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}

#[cfg(target_os = "linux")]
Expand All @@ -95,7 +95,7 @@ pub fn set_tx_time(sock: &impl AsFd) -> io::Result<()> {

#[cfg(not(target_os = "linux"))]
pub fn set_tx_time(_: &impl AsFd) -> io::Result<()> {
Err("unsupported").into_io()
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}

#[cfg(target_os = "linux")]
Expand All @@ -107,5 +107,5 @@ pub fn set_rx_time(sock: &impl AsFd) -> io::Result<()> {

#[cfg(not(target_os = "linux"))]
pub fn set_rx_time(_: &impl AsFd) -> io::Result<()> {
Err("unsupported").into_io()
Err(std::io::Error::from(std::io::ErrorKind::Unsupported))
}
5 changes: 2 additions & 3 deletions dgram/src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::syscalls::RecvData;
use crate::GsoSettings;
use mio::net::UdpSocket;
use std::io::Result;
use std::net::SocketAddr;
Expand Down Expand Up @@ -80,15 +79,15 @@ pub async fn send_to(
socket: &UdpSocket, client_addr: SocketAddr, send_buf: &[u8],
_segment_size: usize, _num_pkts: usize, _tx_time: Option<Instant>,
) -> Result<usize> {
socket.send_to(send_buf, client_addr).await
socket.send_to(send_buf, client_addr)
}

// Signature changes because we can't use MessageFlags outside of a *NIX context
#[cfg(not(target_os = "linux"))]
pub async fn recv_from(
socket: &UdpSocket, read_buf: &mut [u8], _cmsg_space: &mut Vec<u8>,
) -> Result<RecvData> {
let recv = socket.recv(read_buf).await?;
let recv = socket.recv(read_buf)?;

Ok(RecvData {
bytes: recv,
Expand Down
24 changes: 14 additions & 10 deletions dgram/src/syscalls.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use crate::GsoSettings;
use nix::sys::socket::ControlMessageOwned;
use std::net::SocketAddr;
use std::os::fd::AsFd;
use std::time::Instant;
use std::time::SystemTime;

#[cfg(target_os = "linux")]
use super::linux_imports::*;
mod linux {
pub(super) use super::super::linux_imports::*;
pub(super) use std::os::fd::AsFd;
pub(super) use std::time::Instant;
}

#[cfg(target_os = "linux")]
use linux::*;

// 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) };

const INSTANT_ZERO: Instant =
unsafe { std::mem::transmute(std::time::UNIX_EPOCH) };
#[cfg(target_os = "linux")]
pub(crate) type SyscallResult<T> = std::result::Result<T, Errno>;

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -156,7 +160,7 @@ pub struct RecvMetrics {
pub udp_packets_dropped: u64,
}

#[cfg(all(test, target_os = "linux"))]
#[cfg(all(test, target_os = "linux", not(target_os = "android")))]
mod tests {
use nix::cmsg_space;
use nix::sys::socket::sockopt::ReceiveTimestampns;
Expand All @@ -177,7 +181,7 @@ mod tests {
AddressFamily::Inet,
SockType::Datagram,
SockFlag::empty(),
SockProtocol::Udp,
None,
)
.unwrap();
setsockopt(&recv, ReceiveTimestampns, &true)?;
Expand All @@ -189,7 +193,7 @@ mod tests {
AddressFamily::Inet,
SockType::Datagram,
SockFlag::empty(),
SockProtocol::Udp,
None,
)
.unwrap();
connect(send.as_raw_fd(), &localhost).unwrap();
Expand Down
12 changes: 9 additions & 3 deletions dgram/src/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use crate::syscalls::RecvData;
use crate::GsoSettings;
use std::io::Result;
use std::net::SocketAddr;
use std::os::fd::AsFd;
use std::time::Instant;

use crate::async_imports::*;

#[cfg(target_os = "linux")]
mod linux {
pub(super) use super::super::linux_imports::*;
pub(super) use std::os::fd::AsFd;
}

#[cfg(target_os = "linux")]
use super::linux_imports::*;
use linux::*;

#[cfg(target_os = "linux")]
pub async fn send_to(
Expand Down

0 comments on commit 38aa4c5

Please sign in to comment.