From 28c02cabb66cc1d304a4a4197499891c740cbe3c Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 25 Feb 2023 16:59:23 +0100 Subject: [PATCH] Remove usage of target_vendor = "apple" Being deprecated, see: * * --- src/lib.rs | 16 +++++++---- src/socket.rs | 14 +++++---- src/sys/unix.rs | 75 +++++++++++++++++++++++++++++++------------------ tests/socket.rs | 40 +++++++++++++++++--------- 4 files changed, 92 insertions(+), 53 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 359603ab..b0bef66a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -475,10 +475,11 @@ impl TcpKeepalive { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", - windows, + target_os = "windows", ) ))] #[cfg_attr( @@ -491,10 +492,11 @@ impl TcpKeepalive { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", - windows, + target_os = "windows", ) ))) )] @@ -517,9 +519,10 @@ impl TcpKeepalive { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] #[cfg_attr( @@ -532,9 +535,10 @@ impl TcpKeepalive { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))) )] diff --git a/src/socket.rs b/src/socket.rs index fd43dec5..02dfefc5 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -770,7 +770,7 @@ fn set_common_flags(socket: Socket) -> io::Result { socket._set_cloexec(true)?; // On Apple platforms set `NOSIGPIPE`. - #[cfg(target_vendor = "apple")] + #[cfg(any(target_os = "ios", target_os = "macos"))] socket._set_nosigpipe(true)?; Ok(socket) @@ -1794,9 +1794,10 @@ impl Socket { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] #[cfg_attr( @@ -1809,9 +1810,10 @@ impl Socket { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))) )] @@ -1835,9 +1837,10 @@ impl Socket { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] #[cfg_attr( @@ -1850,9 +1853,10 @@ impl Socket { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))) )] diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 6741e782..319957a9 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -13,7 +13,7 @@ use std::marker::PhantomData; use std::mem::{self, size_of, MaybeUninit}; use std::net::Shutdown; use std::net::{Ipv4Addr, Ipv6Addr}; -#[cfg(all(feature = "all", target_vendor = "apple"))] +#[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] use std::num::NonZeroU32; #[cfg(all( feature = "all", @@ -21,8 +21,9 @@ use std::num::NonZeroU32; target_os = "aix", target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))] use std::num::NonZeroUsize; @@ -33,8 +34,9 @@ use std::os::unix::ffi::OsStrExt; target_os = "aix", target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))] use std::os::unix::io::RawFd; @@ -46,7 +48,7 @@ use std::ptr; use std::time::{Duration, Instant}; use std::{io, slice}; -#[cfg(not(target_vendor = "apple"))] +#[cfg(not(any(target_os = "ios", target_os = "macos")))] use libc::ssize_t; use libc::{in6_addr, in_addr}; @@ -117,9 +119,9 @@ pub(crate) use libc::IP_RECVTOS; target_os = "illumos", )))] pub(crate) use libc::IP_TOS; -#[cfg(not(target_vendor = "apple"))] +#[cfg(not(any(target_os = "ios", target_os = "macos")))] pub(crate) use libc::SO_LINGER; -#[cfg(target_vendor = "apple")] +#[cfg(any(target_os = "ios", target_os = "macos"))] pub(crate) use libc::SO_LINGER_SEC as SO_LINGER; pub(crate) use libc::{ ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, @@ -145,11 +147,12 @@ pub(crate) use libc::{ target_os = "freebsd", target_os = "haiku", target_os = "illumos", + target_os = "ios", + target_os = "macos", target_os = "netbsd", + target_os = "nto", target_os = "openbsd", target_os = "solaris", - target_os = "nto", - target_vendor = "apple" )))] pub(crate) use libc::{IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP}; #[cfg(any( @@ -157,10 +160,11 @@ pub(crate) use libc::{IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP}; target_os = "freebsd", target_os = "haiku", target_os = "illumos", + target_os = "ios", + target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris", - target_vendor = "apple", ))] pub(crate) use libc::{ IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP, IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP, @@ -173,9 +177,10 @@ pub(crate) use libc::{ target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] pub(crate) use libc::{TCP_KEEPCNT, TCP_KEEPINTVL}; @@ -183,13 +188,14 @@ pub(crate) use libc::{TCP_KEEPCNT, TCP_KEEPINTVL}; // See this type in the Windows file. pub(crate) type Bool = c_int; -#[cfg(any(target_vendor = "apple", target_os = "nto"))] +#[cfg(any(target_os = "ios", target_os = "macos", target_os = "nto"))] use libc::TCP_KEEPALIVE as KEEPALIVE_TIME; #[cfg(not(any( - target_vendor = "apple", target_os = "haiku", - target_os = "openbsd", + target_os = "ios", + target_os = "macos", target_os = "nto", + target_os = "openbsd", )))] use libc::TCP_KEEPIDLE as KEEPALIVE_TIME; @@ -207,7 +213,7 @@ macro_rules! syscall { } /// Maximum size of a buffer passed to system call like `recv` and `send`. -#[cfg(not(target_vendor = "apple"))] +#[cfg(not(any(target_os = "ios", target_os = "macos")))] const MAX_BUF_LEN: usize = ssize_t::MAX as usize; // The maximum read limit on most posix-like systems is `SSIZE_MAX`, with the @@ -218,7 +224,7 @@ const MAX_BUF_LEN: usize = ssize_t::MAX as usize; // intentionally showing odd behavior by rejecting any read with a size larger // than or equal to INT_MAX. To handle both of these the read size is capped on // both platforms. -#[cfg(target_vendor = "apple")] +#[cfg(any(target_os = "ios", target_os = "macos"))] const MAX_BUF_LEN: usize = c_int::MAX as usize - 1; // TCP_CA_NAME_MAX isn't defined in user space include files(not in libc) @@ -251,11 +257,12 @@ type IovLen = usize; target_os = "fuchsia", target_os = "haiku", target_os = "illumos", + target_os = "ios", + target_os = "macos", target_os = "netbsd", + target_os = "nto", target_os = "openbsd", target_os = "solaris", - target_os = "nto", - target_vendor = "apple", ))] type IovLen = c_int; @@ -939,9 +946,10 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ))] { if let Some(interval) = keepalive.interval { @@ -1177,13 +1185,16 @@ impl crate::Socket { } /// Sets `SO_NOSIGPIPE` on the socket. - #[cfg(all(feature = "all", target_vendor = "apple"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_vendor = "apple"))))] + #[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))) + )] pub fn set_nosigpipe(&self, nosigpipe: bool) -> io::Result<()> { self._set_nosigpipe(nosigpipe) } - #[cfg(target_vendor = "apple")] + #[cfg(any(target_os = "ios", target_os = "macos"))] pub(crate) fn _set_nosigpipe(&self, nosigpipe: bool) -> io::Result<()> { unsafe { setsockopt( @@ -1621,8 +1632,11 @@ impl crate::Socket { /// /// One can use [`libc::if_nametoindex`] to convert an interface alias to an /// index. - #[cfg(all(feature = "all", target_vendor = "apple"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_vendor = "apple"))))] + #[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))) + )] pub fn bind_device_by_index(&self, interface: Option) -> io::Result<()> { let index = interface.map_or(0, NonZeroU32::get); unsafe { setsockopt(self.as_raw(), IPPROTO_IP, libc::IP_BOUND_IF, index) } @@ -1633,8 +1647,11 @@ impl crate::Socket { /// /// Returns `None` if the socket is not bound to any interface, otherwise /// returns an interface index. - #[cfg(all(feature = "all", target_vendor = "apple"))] - #[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_vendor = "apple"))))] + #[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] + #[cfg_attr( + docsrs, + doc(cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))) + )] pub fn device_index(&self) -> io::Result> { let index = unsafe { getsockopt::(self.as_raw(), IPPROTO_IP, libc::IP_BOUND_IF)? }; @@ -1921,8 +1938,9 @@ impl crate::Socket { target_os = "aix", target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))] #[cfg_attr( @@ -1933,8 +1951,9 @@ impl crate::Socket { target_os = "aix", target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))) )] @@ -1950,7 +1969,7 @@ impl crate::Socket { self._sendfile(file.as_raw_fd(), offset as _, length) } - #[cfg(all(feature = "all", target_vendor = "apple"))] + #[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] fn _sendfile( &self, file: RawFd, diff --git a/tests/socket.rs b/tests/socket.rs index d051960d..f207caf4 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -4,8 +4,9 @@ any( target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))] use std::fs::File; @@ -23,8 +24,9 @@ use std::net::{Ipv6Addr, SocketAddrV6}; any( target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))] use std::num::NonZeroUsize; @@ -175,7 +177,7 @@ fn set_nonblocking() { fn assert_common_flags(socket: &Socket, expected: bool) { #[cfg(unix)] assert_close_on_exec(socket, expected); - #[cfg(target_vendor = "apple")] + #[cfg(any(target_os = "ios", target_os = "macos"))] assert_flag_no_sigpipe(socket, expected); #[cfg(windows)] assert_flag_no_inherit(socket, expected); @@ -292,7 +294,7 @@ where assert_eq!(flags & libc::FD_CLOEXEC != 0, want, "CLOEXEC option"); } -#[cfg(all(windows, feature = "all"))] +#[cfg(all(feature = "all", windows))] #[test] fn set_no_inherit() { let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap(); @@ -332,7 +334,7 @@ where ); } -#[cfg(all(feature = "all", target_vendor = "apple"))] +#[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] #[test] fn set_nosigpipe() { let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap(); @@ -346,7 +348,7 @@ fn set_nosigpipe() { } /// Assert that `SO_NOSIGPIPE` is set on `socket`. -#[cfg(target_vendor = "apple")] +#[cfg(any(target_os = "ios", target_os = "macos"))] #[track_caller] pub fn assert_flag_no_sigpipe(socket: &S, want: bool) where @@ -740,10 +742,11 @@ fn tcp_keepalive() { target_os = "dragonfly", target_os = "freebsd", target_os = "fuchsia", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", - windows, + target_os = "windows", ) ))] let params = params.with_interval(Duration::from_secs(30)); @@ -754,9 +757,10 @@ fn tcp_keepalive() { target_os = "dragonfly", target_os = "freebsd", target_os = "fuchsia", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] let params = params.with_retries(10); @@ -778,9 +782,10 @@ fn tcp_keepalive() { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] assert_eq!( @@ -796,9 +801,10 @@ fn tcp_keepalive() { target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", + target_os = "ios", target_os = "linux", + target_os = "macos", target_os = "netbsd", - target_vendor = "apple", ) ))] assert_eq!(socket.keepalive_retries().unwrap(), 10); @@ -838,7 +844,7 @@ fn device() { panic!("failed to bind to any device."); } -#[cfg(all(feature = "all", target_vendor = "apple"))] +#[cfg(all(feature = "all", any(target_os = "ios", target_os = "macos")))] #[test] fn device() { // Some common network interface on macOS. @@ -874,13 +880,15 @@ fn device() { panic!("failed to bind to any device."); } + #[cfg(all( feature = "all", any( target_os = "android", target_os = "freebsd", + target_os = "ios", target_os = "linux", - target_vendor = "apple", + target_os = "macos", ) ))] #[test] @@ -1026,7 +1034,11 @@ fn r#type() { assert_eq!(socket.r#type().unwrap(), Type::DGRAM); // macos doesn't support seqpacket - #[cfg(all(unix, not(target_vendor = "apple"), feature = "all"))] + #[cfg(all( + unix, + not(any(target_os = "ios", target_os = "macos")), + feature = "all", + ))] { let socket = Socket::new(Domain::UNIX, Type::SEQPACKET, None).unwrap(); assert_eq!(socket.r#type().unwrap(), Type::SEQPACKET);