mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-02 21:17:39 +00:00
std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly.
This commit is contained in:
parent
ce609db948
commit
a25b0946a7
@ -86,7 +86,14 @@ impl Socket {
|
|||||||
// flag to atomically create the socket and set it as
|
// flag to atomically create the socket and set it as
|
||||||
// CLOEXEC. On Linux this was added in 2.6.27.
|
// CLOEXEC. On Linux this was added in 2.6.27.
|
||||||
let fd = cvt(libc::socket(fam, ty | libc::SOCK_CLOEXEC, 0))?;
|
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 {
|
} else {
|
||||||
let fd = cvt(libc::socket(fam, ty, 0))?;
|
let fd = cvt(libc::socket(fam, ty, 0))?;
|
||||||
let fd = FileDesc::from_raw_fd(fd);
|
let fd = FileDesc::from_raw_fd(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user