Skip to content

Commit

Permalink
refactor: cfg for socket/sockopt.rs (nix-rust#2225)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC authored Nov 26, 2023
1 parent 51adb30 commit 4e5f089
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cfg_if::cfg_if;
use libc::{self, c_int, c_void, socklen_t};
use std::ffi::{OsStr, OsString};
use std::mem::{self, MaybeUninit};
#[cfg(target_family = "unix")]
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::{AsFd, AsRawFd};

Expand Down Expand Up @@ -329,9 +328,7 @@ cfg_if! {
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave an IPv6 multicast group.
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_DROP_MEMBERSHIP, super::Ipv6MembershipRequest);
} else if #[cfg(any(bsd,
target_os = "illumos",
target_os = "solaris"))] {
} else if #[cfg(any(bsd, solarish))] {
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand Down Expand Up @@ -403,7 +400,7 @@ sockopt_impl!(
libc::IPV6_TCLASS,
libc::c_int
);
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "fuchsia"))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand Down Expand Up @@ -512,12 +509,7 @@ sockopt_impl!(
libc::TCP_KEEPALIVE,
u32
);
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux"
))]
#[cfg(any(freebsdlike, linux_android))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand Down Expand Up @@ -556,7 +548,7 @@ sockopt_impl!(
libc::TCP_KEEPCNT,
u32
);
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "fuchsia"))]
sockopt_impl!(
#[allow(missing_docs)]
// Not documented by Linux!
Expand Down Expand Up @@ -826,12 +818,7 @@ sockopt_impl!(
libc::TCP_CONGESTION,
OsString<[u8; TCP_CA_NAME_MAX]>
);
#[cfg(any(
target_os = "android",
apple_targets,
target_os = "linux",
target_os = "netbsd",
))]
#[cfg(any(linux_android, apple_targets, target_os = "netbsd"))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand All @@ -844,10 +831,9 @@ sockopt_impl!(
bool
);
#[cfg(any(
target_os = "android",
linux_android,
target_os = "freebsd",
apple_targets,
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
))]
Expand Down Expand Up @@ -896,7 +882,7 @@ sockopt_impl!(
libc::IP_RECVDSTADDR,
bool
);
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand Down Expand Up @@ -942,7 +928,7 @@ sockopt_impl!(
libc::SO_TXTIME,
libc::sock_txtime
);
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "fuchsia"))]
sockopt_impl!(
/// Indicates that an unsigned 32-bit value ancillary message (cmsg) should
/// be attached to received skbs indicating the number of packets dropped by
Expand Down Expand Up @@ -990,7 +976,7 @@ sockopt_impl!(
libc::IP_MTU,
libc::c_int
);
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
sockopt_impl!(
/// Set or retrieve the current time-to-live field that is used in every
/// packet sent from this socket.
Expand All @@ -1000,7 +986,7 @@ sockopt_impl!(
libc::IP_TTL,
libc::c_int
);
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
sockopt_impl!(
/// Set the unicast hop limit for the socket.
Ipv6Ttl,
Expand All @@ -1009,7 +995,7 @@ sockopt_impl!(
libc::IPV6_UNICAST_HOPS,
libc::c_int
);
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Expand All @@ -1030,7 +1016,7 @@ sockopt_impl!(
libc::IP_DONTFRAG,
bool
);
#[cfg(any(target_os = "android", apple_targets, target_os = "linux",))]
#[cfg(any(linux_android, apple_targets))]
sockopt_impl!(
/// Set "don't fragment packet" flag on the IPv6 packet.
Ipv6DontFrag,
Expand Down

0 comments on commit 4e5f089

Please sign in to comment.