about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorMathieu Poumeyrol <kali@zoy.org>2016-09-12 21:38:28 +0200
committerMathieu Poumeyrol <mathieu.poumeyrol@snips.ai>2016-09-28 19:43:11 +0200
commit6f6e261e20fd1a770cb3477205c192dd158897f8 (patch)
tree394deb3bf79da2d5e4444ab21fe3aff44cd3b933 /src/libstd/sys
parenteee2d04d877fe909309c39b6bdf711dc586d0a1e (diff)
downloadrust-6f6e261e20fd1a770cb3477205c192dd158897f8.tar.gz
rust-6f6e261e20fd1a770cb3477205c192dd158897f8.zip
set SO_NOSIGPIPE on apple platforms
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/net.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index ec7ccdf5894..ad287bbec38 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -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() {}
@@ -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)
         }
     }