Skip to content

Commit 5980d5b

Browse files
committed
use MSG_NOSIGNAL from liblibc
1 parent ed5e542 commit 5980d5b

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/libstd/sys/common/net.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
4343
use sys::net::netc::IPV6_DROP_MEMBERSHIP;
4444

4545
#[cfg(target_os = "linux")]
46-
const MSG_NOSIGNAL: c_int = 0x4000;
46+
use libc::MSG_NOSIGNAL;
4747
#[cfg(not(target_os = "linux"))]
4848
const MSG_NOSIGNAL: c_int = 0x0; // unused dummy value
4949

@@ -226,12 +226,11 @@ impl TcpStream {
226226

227227
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
228228
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
229-
let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
230229
let ret = cvt(unsafe {
231230
c::send(*self.inner.as_inner(),
232231
buf.as_ptr() as *const c_void,
233232
len,
234-
flags)
233+
MSG_NOSIGNAL)
235234
})?;
236235
Ok(ret as usize)
237236
}
@@ -452,11 +451,10 @@ impl UdpSocket {
452451
pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result<usize> {
453452
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
454453
let (dstp, dstlen) = dst.into_inner();
455-
let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
456454
let ret = cvt(unsafe {
457455
c::sendto(*self.inner.as_inner(),
458456
buf.as_ptr() as *const c_void, len,
459-
flags, dstp, dstlen)
457+
MSG_NOSIGNAL, dstp, dstlen)
460458
})?;
461459
Ok(ret as usize)
462460
}
@@ -576,12 +574,11 @@ impl UdpSocket {
576574

577575
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
578576
let len = cmp::min(buf.len(), <wrlen_t>::max_value() as usize) as wrlen_t;
579-
let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
580577
let ret = cvt(unsafe {
581578
c::send(*self.inner.as_inner(),
582579
buf.as_ptr() as *const c_void,
583580
len,
584-
flags)
581+
MSG_NOSIGNAL)
585582
})?;
586583
Ok(ret as usize)
587584
}

src/libstd/sys/unix/ext/net.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use sys::net::Socket;
2929
use sys_common::{AsInner, FromInner, IntoInner};
3030

3131
#[cfg(target_os = "linux")]
32-
const MSG_NOSIGNAL: libc::c_int = 0x4000;
32+
use libc::MSG_NOSIGNAL;
3333
#[cfg(not(target_os = "linux"))]
3434
const MSG_NOSIGNAL: libc::c_int = 0x0; // unused dummy value
3535

@@ -691,12 +691,11 @@ impl UnixDatagram {
691691
fn inner(d: &UnixDatagram, buf: &[u8], path: &Path) -> io::Result<usize> {
692692
unsafe {
693693
let (addr, len) = sockaddr_un(path)?;
694-
let flags = if cfg!(target_os = "linux") { MSG_NOSIGNAL } else { 0 };
695694

696695
let count = cvt(libc::sendto(*d.0.as_inner(),
697696
buf.as_ptr() as *const _,
698697
buf.len(),
699-
flags,
698+
MSG_NOSIGNAL,
700699
&addr as *const _ as *const _,
701700
len))?;
702701
Ok(count as usize)

0 commit comments

Comments
 (0)