Skip to content

Fix compilation with --cfg doc #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ impl TcpKeepalive {
#[cfg(all(
feature = "all",
any(
doc,
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
Expand Down
19 changes: 7 additions & 12 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Socket {
/// This function sets the same flags as in done for [`Socket::new`],
/// [`Socket::pair_raw`] can be used if you don't want to set those flags.
#[doc = man_links!(unix: socketpair(2))]
#[cfg(any(doc, all(feature = "all", unix)))]
#[cfg(all(feature = "all", unix))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
pub fn pair(
domain: Domain,
Expand All @@ -164,7 +164,7 @@ impl Socket {
/// Creates a pair of sockets which are connected to each other.
///
/// This function corresponds to `socketpair(2)`.
#[cfg(any(doc, all(feature = "all", unix)))]
#[cfg(all(feature = "all", unix))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
pub fn pair_raw(
domain: Domain,
Expand Down Expand Up @@ -1091,7 +1091,7 @@ impl Socket {
/// For more information about this option, see [`set_ip_transparent`].
///
/// [`set_ip_transparent`]: Socket::set_ip_transparent
#[cfg(any(doc, all(feature = "all", target_os = "linux")))]
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn ip_transparent(&self) -> io::Result<bool> {
unsafe {
Expand All @@ -1115,7 +1115,7 @@ impl Socket {
///
/// TProxy redirection with the iptables TPROXY target also
/// requires that this option be set on the redirected socket.
#[cfg(any(doc, all(feature = "all", target_os = "linux")))]
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn set_ip_transparent(&self, transparent: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -1737,12 +1737,9 @@ impl Socket {
///
/// This returns the value of `TCP_KEEPALIVE` on macOS and iOS and `TCP_KEEPIDLE` on all other
/// supported Unix operating systems.
#[cfg(any(
doc,
all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
)
#[cfg(all(
feature = "all",
not(any(windows, target_os = "haiku", target_os = "openbsd"))
))]
#[cfg_attr(
docsrs,
Expand All @@ -1763,7 +1760,6 @@ impl Socket {
#[cfg(all(
feature = "all",
any(
doc,
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
Expand Down Expand Up @@ -1805,7 +1801,6 @@ impl Socket {
#[cfg(all(
feature = "all",
any(
doc,
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
Expand Down
12 changes: 8 additions & 4 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ pub(crate) fn socket(family: c_int, ty: c_int, protocol: c_int) -> io::Result<So
syscall!(socket(family, ty, protocol))
}

#[cfg(feature = "all")]
#[cfg(all(feature = "all", unix))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
pub(crate) fn socketpair(family: c_int, ty: c_int, protocol: c_int) -> io::Result<[Socket; 2]> {
let mut fds = [0, 0];
syscall!(socketpair(family, ty, protocol, fds.as_mut_ptr())).map(|_| fds)
Expand Down Expand Up @@ -898,8 +899,11 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
}
}

#[cfg(feature = "all")]
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
#[cfg(all(feature = "all", not(any(target_os = "haiku", target_os = "openbsd"))))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", not(any(target_os = "haiku", target_os = "openbsd")))))
)]
pub(crate) fn keepalive_time(fd: Socket) -> io::Result<Duration> {
unsafe {
getsockopt::<c_int>(fd, IPPROTO_TCP, KEEPALIVE_TIME)
Expand Down Expand Up @@ -1158,7 +1162,7 @@ impl crate::Socket {
}

/// Sets `SO_NOSIGPIPE` on the socket.
#[cfg(all(feature = "all", any(doc, target_vendor = "apple")))]
#[cfg(all(feature = "all", target_vendor = "apple"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_vendor = "apple"))))]
pub fn set_nosigpipe(&self, nosigpipe: bool) -> io::Result<()> {
self._set_nosigpipe(nosigpipe)
Expand Down
2 changes: 1 addition & 1 deletion tests/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ fn tcp_congestion() {
let cur_tcp_ca = cur_tcp_ca.splitn(2, |num| *num == 0).next().unwrap();
const OPTIONS: [&[u8]; 2] = [
b"cubic",
#[cfg(target_os = "linux")] // or Android.
#[cfg(target_os = "linux")]
b"reno",
#[cfg(target_os = "freebsd")]
b"newreno",
Expand Down