Skip to content

Commit

Permalink
build: disable recv/sendmmsg on apple, solaris, hurd, vita platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuetuopay committed Feb 8, 2024
1 parent b8670dc commit f6cfed8
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 22 deletions.
66 changes: 60 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,14 +732,32 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdrMut<'name, 'bufs, 'control> {
///
/// This wraps `mmsghdr` on Unix. Also see [`MmsgHdrMut`] for the variant used
/// by `recvmmsg(2)`.
#[cfg(not(target_os = "redox"))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
pub struct MmsgHdr<'addr, 'bufs, 'control> {
inner: Vec<sys::mmsghdr>,
#[allow(clippy::type_complexity)]
_lifetimes: PhantomData<(&'addr SockAddr, &'bufs IoSlice<'bufs>, &'control [u8])>,
}

#[cfg(not(target_os = "redox"))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
impl<'addr, 'bufs, 'control> MmsgHdr<'addr, 'bufs, 'control> {
/// Create a new `MmsgHdr` with all empty/zero fields.
#[allow(clippy::new_without_default)]
Expand Down Expand Up @@ -792,7 +810,16 @@ impl<'addr, 'bufs, 'control> MmsgHdr<'addr, 'bufs, 'control> {
}
}

#[cfg(not(target_os = "redox"))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
impl<'name, 'bufs, 'control> fmt::Debug for MmsgHdr<'name, 'bufs, 'control> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"MmsgHdr".fmt(fmt)
Expand All @@ -803,7 +830,16 @@ impl<'name, 'bufs, 'control> fmt::Debug for MmsgHdr<'name, 'bufs, 'control> {
///
/// This wraps `mmsghdr` on Unix. Also see [`MmsgHdr`] for the variant used by
/// `sendmmsg(2)`.
#[cfg(not(target_os = "redox"))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
pub struct MmsgHdrMut<'addr, 'bufs, 'control> {
inner: Vec<sys::mmsghdr>,
#[allow(clippy::type_complexity)]
Expand All @@ -814,7 +850,16 @@ pub struct MmsgHdrMut<'addr, 'bufs, 'control> {
)>,
}

#[cfg(not(target_os = "redox"))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
impl<'addr, 'bufs, 'control> MmsgHdrMut<'addr, 'bufs, 'control> {
/// Create a new `MmsgHdrMut` with all empty/zero fields.
#[allow(clippy::new_without_default)]
Expand Down Expand Up @@ -869,7 +914,16 @@ impl<'addr, 'bufs, 'control> MmsgHdrMut<'addr, 'bufs, 'control> {
}
}

#[cfg(not(target_os = "redox"))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
impl<'name, 'bufs, 'control> fmt::Debug for MmsgHdrMut<'name, 'bufs, 'control> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"MmsgHdrMut".fmt(fmt)
Expand Down
115 changes: 105 additions & 10 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ use std::os::windows::io::{FromRawSocket, IntoRawSocket};
use std::time::Duration;

use crate::sys::{self, c_int, getsockopt, setsockopt, Bool};
#[cfg(all(unix, not(target_os = "redox")))]
use crate::MsgHdrMut;
use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type};
#[cfg(not(target_os = "redox"))]
use crate::{MaybeUninitSlice, MsgHdr, RecvFlags};
#[cfg(all(unix, not(target_os = "redox")))]
use crate::{MmsgHdr, MmsgHdrMut, MsgHdrMut};
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
use crate::{MmsgHdr, MmsgHdrMut};

/// Owned wrapper around a system socket.
///
Expand Down Expand Up @@ -587,8 +598,29 @@ impl Socket {
}

/// Receive multiple messages in a single call.
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg_attr(docsrs, doc(cfg(all(unix, not(target_os = "redox")))))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
)))
)]
pub fn recv_multiple_from(
&self,
msgs: &mut [MaybeUninitSlice<'_>],
Expand Down Expand Up @@ -655,8 +687,29 @@ impl Socket {

/// Receive multiple messages from a socket using a message structure.
#[doc = man_links!(recvmmsg(2))]
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg_attr(docsrs, doc(cfg(all(unix, not(target_os = "redox")))))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
)))
)]
pub fn recvmmsg(
&self,
msgs: &mut MmsgHdrMut<'_, '_, '_>,
Expand Down Expand Up @@ -766,8 +819,29 @@ impl Socket {

/// Send multiple data to multiple peers listening on `addrs`. Return the amount of bytes
/// written for each message.
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg_attr(docsrs, doc(cfg(all(unix, not(target_os = "redox")))))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
)))
)]
pub fn send_multiple_to(
&self,
msgs: &[IoSlice<'_>],
Expand All @@ -787,8 +861,29 @@ impl Socket {

/// Send multiple messages on a socket using a multiple message structure.
#[doc = man_links!(sendmmsg(2))]
#[cfg(not(target_os = "redox"))]
#[cfg_attr(docsrs, doc(cfg(not(target_os = "redox"))))]
#[cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
))]
#[cfg_attr(
docsrs,
doc(cfg(all(
unix,
not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
))
)))
)]
pub fn sendmmsg(&self, msgs: &MmsgHdr<'_, '_, '_>, flags: sys::c_int) -> io::Result<usize> {
sys::sendmmsg(self.as_raw(), msgs, flags)
}
Expand Down
52 changes: 46 additions & 6 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ use libc::ssize_t;
use libc::{in6_addr, in_addr};

use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type};
#[cfg(not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
)))]
use crate::{MmsgHdr, MmsgHdrMut};
#[cfg(not(target_os = "redox"))]
use crate::{MmsgHdr, MmsgHdrMut, MsgHdr, MsgHdrMut, RecvFlags};
use crate::{MsgHdr, MsgHdrMut, RecvFlags};

pub(crate) use libc::c_int;

Expand Down Expand Up @@ -671,8 +679,16 @@ pub(crate) fn unix_sockaddr(path: &Path) -> io::Result<SockAddr> {
}

// Used in `MsgHdr`.
#[cfg(not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
)))]
pub(crate) use libc::mmsghdr;
#[cfg(not(target_os = "redox"))]
pub(crate) use libc::{mmsghdr, msghdr};
pub(crate) use libc::msghdr;

#[cfg(not(target_os = "redox"))]
pub(crate) fn set_msghdr_name(msg: &mut msghdr, name: &SockAddr) {
Expand Down Expand Up @@ -1067,7 +1083,13 @@ pub(crate) fn recvmsg(
syscall!(recvmsg(fd, &mut msg.inner, flags)).map(|n| n as usize)
}

#[cfg(not(target_os = "redox"))]
#[cfg(not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
)))]
pub(crate) fn recv_multiple_from(
fd: Socket,
msgs: &mut [crate::MaybeUninitSlice<'_>],
Expand Down Expand Up @@ -1096,7 +1118,13 @@ pub(crate) fn recv_multiple_from(
Ok(rets)
}

#[cfg(not(target_os = "redox"))]
#[cfg(not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
)))]
pub(crate) fn recvmmsg(
fd: Socket,
msgs: &mut MmsgHdrMut<'_, '_, '_>,
Expand Down Expand Up @@ -1174,7 +1202,13 @@ pub(crate) fn sendmsg(fd: Socket, msg: &MsgHdr<'_, '_, '_>, flags: c_int) -> io:
syscall!(sendmsg(fd, &msg.inner, flags)).map(|n| n as usize)
}

#[cfg(not(target_os = "redox"))]
#[cfg(not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
)))]
pub(crate) fn send_multiple_to(
fd: Socket,
msgs: &[IoSlice<'_>],
Expand All @@ -1189,7 +1223,13 @@ pub(crate) fn send_multiple_to(
.collect())
}

#[cfg(not(target_os = "redox"))]
#[cfg(not(any(
target_os = "redox",
target_os = "solaris",
target_os = "hurd",
target_os = "vita",
target_vendor = "apple"
)))]
pub(crate) fn sendmmsg(fd: Socket, msgs: &MmsgHdr<'_, '_, '_>, flags: c_int) -> io::Result<usize> {
syscall!(sendmmsg(
fd,
Expand Down

0 comments on commit f6cfed8

Please sign in to comment.