Skip to content

Commit

Permalink
Platform flags
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Dec 30, 2024
1 parent 07d3266 commit 95ce7ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions apps/src/recvfrom.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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<RecvData> {
match socket.recv_from(buf) {
Expand Down
4 changes: 3 additions & 1 deletion dgram/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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")]
Expand Down Expand Up @@ -45,6 +46,7 @@ pub struct RecvMsgSettings<'c> {
pub cmsg_space: &'c mut Vec<u8>,
}

#[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<u8>) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions dgram/src/syscalls.rs
Original file line number Diff line number Diff line change
@@ -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<T> = std::result::Result<T, Errno>;

Expand All @@ -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<SockaddrStorage>,
Expand All @@ -27,7 +27,7 @@ fn raw_send_to(
sendmsg(
borrowed.as_raw_fd(),
&iov,
&cmsgs,
cmsgs,
msg_flags,
client_addr.as_ref(),
)
Expand Down

0 comments on commit 95ce7ca

Please sign in to comment.