Rollup merge of #124470 - devnexen:no_sigpipe_fbsd, r=workingjubilee

std::net: Socket::new_raw now set to SO_NOSIGPIPE on freebsd.
This commit is contained in:
Jubilee 2024-05-08 00:37:09 -07:00 committed by GitHub
commit bc42f25b04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -86,7 +86,14 @@ impl Socket {
// flag to atomically create the socket and set it as
// CLOEXEC. On Linux this was added in 2.6.27.
let fd = cvt(libc::socket(fam, ty | libc::SOCK_CLOEXEC, 0))?;
Ok(Socket(FileDesc::from_raw_fd(fd)))
let socket = Socket(FileDesc::from_raw_fd(fd));
// DragonFlyBSD, FreeBSD and NetBSD use `SO_NOSIGPIPE` as a `setsockopt`
// flag to disable `SIGPIPE` emission on socket.
#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "dragonfly"))]
setsockopt(&socket, libc::SOL_SOCKET, libc::SO_NOSIGPIPE, 1)?;
Ok(socket)
} else {
let fd = cvt(libc::socket(fam, ty, 0))?;
let fd = FileDesc::from_raw_fd(fd);