From 0c227041a7faced80a532966dc085961fb46073a Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 9 Oct 2023 01:41:20 +0900 Subject: [PATCH] Provide {get,set}_socket_nosigpipe on NetBSD and DragonFly BSD (#870) - https://man.netbsd.org/setsockopt.2 - https://github.com/DragonFlyBSD/DragonFlyBSD/commit/89233cfd97300c5309bc96594ef1b873b24d60c2 --- src/backend/libc/c.rs | 5 +++++ src/backend/libc/net/sockopt.rs | 4 ++-- src/net/sockopt.rs | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs index 98e7c9d20..4fa654457 100644 --- a/src/backend/libc/c.rs +++ b/src/backend/libc/c.rs @@ -86,6 +86,11 @@ pub(crate) const XCASE: tcflag_t = linux_raw_sys::general::XCASE as _; #[cfg(target_os = "aix")] pub(crate) const MSG_DONTWAIT: c_int = libc::MSG_NONBLOCK; +// TODO: Remove once https://github.com/rust-lang/libc/pull/3377 is merged and released. +#[cfg(target_os = "netbsd")] +#[cfg(feature = "net")] +pub(crate) const SO_NOSIGPIPE: c_int = 0x0800; + // On PowerPC, the regular `termios` has the `termios2` fields and there is no // `termios2`. linux-raw-sys has aliases `termios2` to `termios` to cover this // difference, but we still need to manually import it since `libc` doesn't diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs index 2dc84b908..ff28b8db8 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -301,13 +301,13 @@ pub(crate) fn get_socket_timeout(fd: BorrowedFd<'_>, id: Timeout) -> io::Result< } } -#[cfg(any(apple, target_os = "freebsd"))] +#[cfg(any(apple, freebsdlike, target_os = "netbsd"))] #[inline] pub(crate) fn get_socket_nosigpipe(fd: BorrowedFd<'_>) -> io::Result { getsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE).map(to_bool) } -#[cfg(any(apple, target_os = "freebsd"))] +#[cfg(any(apple, freebsdlike, target_os = "netbsd"))] #[inline] pub(crate) fn set_socket_nosigpipe(fd: BorrowedFd<'_>, val: bool) -> io::Result<()> { setsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE, from_bool(val)) diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index f43a75e1c..e2cd4e91a 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -341,7 +341,7 @@ pub fn get_socket_error(fd: Fd) -> io::Result> { /// See the [module-level documentation] for more. /// /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions -#[cfg(any(apple, target_os = "freebsd"))] +#[cfg(any(apple, freebsdlike, target_os = "netbsd"))] #[doc(alias = "SO_NOSIGPIPE")] #[inline] pub fn get_socket_nosigpipe(fd: Fd) -> io::Result { @@ -353,7 +353,7 @@ pub fn get_socket_nosigpipe(fd: Fd) -> io::Result { /// See the [module-level documentation] for more. /// /// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions -#[cfg(any(apple, target_os = "freebsd"))] +#[cfg(any(apple, freebsdlike, target_os = "netbsd"))] #[doc(alias = "SO_NOSIGPIPE")] #[inline] pub fn set_socket_nosigpipe(fd: Fd, value: bool) -> io::Result<()> {