Skip to content

Commit 06c3782

Browse files
committed
Provide {get,set}_socket_nosigpipe on NetBSD and DragonFly BSD
- https://man.netbsd.org/setsockopt.2 - DragonFlyBSD/DragonFlyBSD@89233cf
1 parent a00dbd0 commit 06c3782

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/backend/libc/c.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ pub(crate) const XCASE: tcflag_t = linux_raw_sys::general::XCASE as _;
8686
#[cfg(target_os = "aix")]
8787
pub(crate) const MSG_DONTWAIT: c_int = libc::MSG_NONBLOCK;
8888

89+
// TODO: Remove once https://github.com/rust-lang/libc/pull/3377 is merged and released.
90+
#[cfg(target_os = "netbsd")]
91+
#[cfg(feature = "net")]
92+
pub(crate) const SO_NOSIGPIPE: c_int = 0x0800;
93+
8994
// On PowerPC, the regular `termios` has the `termios2` fields and there is no
9095
// `termios2`. linux-raw-sys has aliases `termios2` to `termios` to cover this
9196
// difference, but we still need to manually import it since `libc` doesn't

src/backend/libc/net/sockopt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ pub(crate) fn get_socket_timeout(fd: BorrowedFd<'_>, id: Timeout) -> io::Result<
301301
}
302302
}
303303

304-
#[cfg(any(apple, target_os = "freebsd"))]
304+
#[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
305305
#[inline]
306306
pub(crate) fn get_socket_nosigpipe(fd: BorrowedFd<'_>) -> io::Result<bool> {
307307
getsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE).map(to_bool)
308308
}
309309

310-
#[cfg(any(apple, target_os = "freebsd"))]
310+
#[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
311311
#[inline]
312312
pub(crate) fn set_socket_nosigpipe(fd: BorrowedFd<'_>, val: bool) -> io::Result<()> {
313313
setsockopt(fd, c::SOL_SOCKET, c::SO_NOSIGPIPE, from_bool(val))

src/net/sockopt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn get_socket_error<Fd: AsFd>(fd: Fd) -> io::Result<Result<(), io::Errno>> {
341341
/// See the [module-level documentation] for more.
342342
///
343343
/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
344-
#[cfg(any(apple, target_os = "freebsd"))]
344+
#[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
345345
#[doc(alias = "SO_NOSIGPIPE")]
346346
#[inline]
347347
pub fn get_socket_nosigpipe<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
@@ -353,7 +353,7 @@ pub fn get_socket_nosigpipe<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
353353
/// See the [module-level documentation] for more.
354354
///
355355
/// [module-level documentation]: self#references-for-get_socket_-and-set_socket_-functions
356-
#[cfg(any(apple, target_os = "freebsd"))]
356+
#[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
357357
#[doc(alias = "SO_NOSIGPIPE")]
358358
#[inline]
359359
pub fn set_socket_nosigpipe<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {

0 commit comments

Comments
 (0)