Skip to content
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

Provide {get,set}_socket_nosigpipe on NetBSD and DragonFly BSD #870

Merged
merged 1 commit into from
Oct 8, 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
5 changes: 5 additions & 0 deletions src/backend/libc/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/backend/libc/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
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))
Expand Down
4 changes: 2 additions & 2 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ pub fn get_socket_error<Fd: AsFd>(fd: Fd) -> io::Result<Result<(), io::Errno>> {
/// 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: AsFd>(fd: Fd) -> io::Result<bool> {
Expand All @@ -353,7 +353,7 @@ pub fn get_socket_nosigpipe<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
/// 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: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
Expand Down