diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-06-24 11:20:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-24 11:20:05 +0200 |
| commit | 24cd817cfa1e63242a6936c8faf64a47085ecf83 (patch) | |
| tree | 5e728954acbe21301fc69ce1537fe722ea7ca92e /library/std/src/os/unix/net/stream.rs | |
| parent | 99b18d6c5062449db8e7ccded4cb69b555a239c3 (diff) | |
| parent | 426ab142507fca8704d934da556f1c96b0fd61b2 (diff) | |
| download | rust-24cd817cfa1e63242a6936c8faf64a47085ecf83.tar.gz rust-24cd817cfa1e63242a6936c8faf64a47085ecf83.zip | |
Rollup merge of #140005 - mlowicki:patch-1, r=tgross35
Set MSG_NOSIGNAL for UnixStream https://github.com/rust-lang/rust/issues/139956 Same logic as for https://github.com/rust-lang/rust/blob/1f76d219c906f0112bb1872f33aa977164c53fa6/library/std/src/sys/net/connection/socket.rs#L399-L405.
Diffstat (limited to 'library/std/src/os/unix/net/stream.rs')
| -rw-r--r-- | library/std/src/os/unix/net/stream.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 1bd3bab5e37..035768a6fab 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -1,3 +1,18 @@ +cfg_if::cfg_if! { + if #[cfg(any( + target_os = "linux", target_os = "android", + target_os = "hurd", + target_os = "dragonfly", target_os = "freebsd", + target_os = "openbsd", target_os = "netbsd", + target_os = "solaris", target_os = "illumos", + target_os = "haiku", target_os = "nto", + target_os = "cygwin"))] { + use libc::MSG_NOSIGNAL; + } else { + const MSG_NOSIGNAL: core::ffi::c_int = 0x0; + } +} + use super::{SocketAddr, sockaddr_un}; #[cfg(any(doc, target_os = "android", target_os = "linux"))] use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to}; @@ -41,6 +56,12 @@ use crate::time::Duration; /// Ok(()) /// } /// ``` +/// +/// # `SIGPIPE` +/// +/// Writes to the underlying socket in `SOCK_STREAM` mode are made with `MSG_NOSIGNAL` flag. +/// This suppresses the emission of the `SIGPIPE` signal when writing to disconnected socket. +/// In some cases getting a `SIGPIPE` would trigger process termination. #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixStream(pub(super) Socket); @@ -633,7 +654,7 @@ impl io::Write for UnixStream { #[stable(feature = "unix_socket", since = "1.10.0")] impl<'a> io::Write for &'a UnixStream { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { - self.0.write(buf) + self.0.send_with_flags(buf, MSG_NOSIGNAL) } fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { |
