Skip to content

Commit

Permalink
set SO_NOSIGPIPE on apple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kali committed Sep 28, 2016
1 parent eee2d04 commit 6f6e261
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/libstd/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ use libc::SOCK_CLOEXEC;
#[cfg(not(target_os = "linux"))]
const SOCK_CLOEXEC: c_int = 0;

// Another conditional contant for name resolution: Macos et iOS use
// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket.
// Other platforms do otherwise.
#[cfg(target_vendor = "apple")]
use libc::SO_NOSIGPIPE;
#[cfg(not(target_vendor = "apple"))]
const SO_NOSIGPIPE: c_int = 0;

pub struct Socket(FileDesc);

pub fn init() {}
Expand Down Expand Up @@ -81,7 +89,11 @@ impl Socket {
let fd = cvt(libc::socket(fam, ty, 0))?;
let fd = FileDesc::new(fd);
fd.set_cloexec()?;
Ok(Socket(fd))
let socket = Socket(fd);
if cfg!(target_vendor = "apple") {
setsockopt(&socket, libc::SOL_SOCKET, SO_NOSIGPIPE, 1)?;
}
Ok(socket)
}
}

Expand Down

0 comments on commit 6f6e261

Please sign in to comment.