about summary refs log tree commit diff
path: root/src/libstd/sys/common
diff options
context:
space:
mode:
authorMathieu Poumeyrol <kali@zoy.org>2016-09-27 10:16:49 -0400
committerMathieu Poumeyrol <mathieu.poumeyrol@snips.ai>2016-09-28 19:43:11 +0200
commited5e5428192f6f72afcb4becc3d78a18133613df (patch)
tree9d800b1ae90dcff672a7acbaf228213616d91a2a /src/libstd/sys/common
parent6f6e261e20fd1a770cb3477205c192dd158897f8 (diff)
downloadrust-ed5e5428192f6f72afcb4becc3d78a18133613df.tar.gz
rust-ed5e5428192f6f72afcb4becc3d78a18133613df.zip
MSG_NOSIGNAL on linux
Diffstat (limited to 'src/libstd/sys/common')
-rw-r--r--src/libstd/sys/common/net.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs
index 18280e497db..d0d387c6ed9 100644
--- a/src/libstd/sys/common/net.rs
+++ b/src/libstd/sys/common/net.rs
@@ -42,6 +42,11 @@ use sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
               target_os = "solaris", target_os = "haiku")))]
 use sys::net::netc::IPV6_DROP_MEMBERSHIP;
 
+#[cfg(target_os = "linux")]
+const MSG_NOSIGNAL: c_int = 0x4000;
+#[cfg(not(target_os = "linux"))]
+const MSG_NOSIGNAL: c_int = 0x0; // unused dummy value
+
 ////////////////////////////////////////////////////////////////////////////////
 // sockaddr and misc bindings
 ////////////////////////////////////////////////////////////////////////////////
@@ -221,11 +226,12 @@ impl TcpStream {
 
     pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
         let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
+        let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
         let ret = cvt(unsafe {
             c::send(*self.inner.as_inner(),
                     buf.as_ptr() as *const c_void,
                     len,
-                    0)
+                    flags)
         })?;
         Ok(ret as usize)
     }
@@ -446,10 +452,11 @@ impl UdpSocket {
     pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result<usize> {
         let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
         let (dstp, dstlen) = dst.into_inner();
+        let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
         let ret = cvt(unsafe {
             c::sendto(*self.inner.as_inner(),
                       buf.as_ptr() as *const c_void, len,
-                      0, dstp, dstlen)
+                      flags, dstp, dstlen)
         })?;
         Ok(ret as usize)
     }
@@ -569,11 +576,12 @@ impl UdpSocket {
 
     pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
         let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
+        let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
         let ret = cvt(unsafe {
             c::send(*self.inner.as_inner(),
                     buf.as_ptr() as *const c_void,
                     len,
-                    0)
+                    flags)
         })?;
         Ok(ret as usize)
     }