Auto merge of #36824 - kali:master, r=alexcrichton
SO_NOSIGPIPE and MSG_NOSIGNAL (rebased #36426) I'm not sure what happened when I pushed a rebased branch on #36426 , github closed it...
This commit is contained in:
commit
5045d4e396
4 changed files with 28 additions and 6 deletions
|
@ -1 +1 @@
|
|||
Subproject commit eb708c020826a8d792a5a5275be147aabe47fe24
|
||||
Subproject commit b474785561d58efbd27add9d22339dcabad742ad
|
|
@ -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")]
|
||||
use libc::MSG_NOSIGNAL;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
const MSG_NOSIGNAL: c_int = 0x0; // unused dummy value
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// sockaddr and misc bindings
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -225,7 +230,7 @@ impl TcpStream {
|
|||
c::send(*self.inner.as_inner(),
|
||||
buf.as_ptr() as *const c_void,
|
||||
len,
|
||||
0)
|
||||
MSG_NOSIGNAL)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
}
|
||||
|
@ -449,7 +454,7 @@ impl UdpSocket {
|
|||
let ret = cvt(unsafe {
|
||||
c::sendto(*self.inner.as_inner(),
|
||||
buf.as_ptr() as *const c_void, len,
|
||||
0, dstp, dstlen)
|
||||
MSG_NOSIGNAL, dstp, dstlen)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
}
|
||||
|
@ -573,7 +578,7 @@ impl UdpSocket {
|
|||
c::send(*self.inner.as_inner(),
|
||||
buf.as_ptr() as *const c_void,
|
||||
len,
|
||||
0)
|
||||
MSG_NOSIGNAL)
|
||||
})?;
|
||||
Ok(ret as usize)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,11 @@ use sys::cvt;
|
|||
use sys::net::Socket;
|
||||
use sys_common::{AsInner, FromInner, IntoInner};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::MSG_NOSIGNAL;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
const MSG_NOSIGNAL: libc::c_int = 0x0; // unused dummy value
|
||||
|
||||
fn sun_path_offset() -> usize {
|
||||
unsafe {
|
||||
// Work with an actual instance of the type since using a null pointer is UB
|
||||
|
@ -690,7 +695,7 @@ impl UnixDatagram {
|
|||
let count = cvt(libc::sendto(*d.0.as_inner(),
|
||||
buf.as_ptr() as *const _,
|
||||
buf.len(),
|
||||
0,
|
||||
MSG_NOSIGNAL,
|
||||
&addr as *const _ as *const _,
|
||||
len))?;
|
||||
Ok(count as usize)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue