Skip to content

Commit

Permalink
Rollup merge of rust-lang#124470 - devnexen:no_sigpipe_fbsd, r=workin…
Browse files Browse the repository at this point in the history
…gjubilee

std::net: Socket::new_raw now set to SO_NOSIGPIPE on freebsd.
  • Loading branch information
workingjubilee committed May 8, 2024
2 parents 5ce96b1 + a25b094 commit d970e95
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/std/src/sys/pal/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d970e95

Please sign in to comment.