@@ -42,6 +42,11 @@ use sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP;
42
42
target_os = "solaris" , target_os = "haiku" ) ) ) ]
43
43
use sys:: net:: netc:: IPV6_DROP_MEMBERSHIP ;
44
44
45
+ #[ cfg( target_os = "linux" ) ]
46
+ const MSG_NOSIGNAL : c_int = 0x4000 ;
47
+ #[ cfg( not( target_os = "linux" ) ) ]
48
+ const MSG_NOSIGNAL : c_int = 0x0 ; // unused dummy value
49
+
45
50
////////////////////////////////////////////////////////////////////////////////
46
51
// sockaddr and misc bindings
47
52
////////////////////////////////////////////////////////////////////////////////
@@ -221,11 +226,12 @@ impl TcpStream {
221
226
222
227
pub fn write ( & self , buf : & [ u8 ] ) -> io:: Result < usize > {
223
228
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 } ;
224
230
let ret = cvt ( unsafe {
225
231
c:: send ( * self . inner . as_inner ( ) ,
226
232
buf. as_ptr ( ) as * const c_void ,
227
233
len,
228
- 0 )
234
+ flags )
229
235
} ) ?;
230
236
Ok ( ret as usize )
231
237
}
@@ -446,10 +452,11 @@ impl UdpSocket {
446
452
pub fn send_to ( & self , buf : & [ u8 ] , dst : & SocketAddr ) -> io:: Result < usize > {
447
453
let len = cmp:: min ( buf. len ( ) , <wrlen_t >:: max_value ( ) as usize ) as wrlen_t ;
448
454
let ( dstp, dstlen) = dst. into_inner ( ) ;
455
+ let flags = if cfg ! ( target_os = "linux" ) { MSG_NOSIGNAL } else { 0 } ;
449
456
let ret = cvt ( unsafe {
450
457
c:: sendto ( * self . inner . as_inner ( ) ,
451
458
buf. as_ptr ( ) as * const c_void , len,
452
- 0 , dstp, dstlen)
459
+ flags , dstp, dstlen)
453
460
} ) ?;
454
461
Ok ( ret as usize )
455
462
}
@@ -569,11 +576,12 @@ impl UdpSocket {
569
576
570
577
pub fn send ( & self , buf : & [ u8 ] ) -> io:: Result < usize > {
571
578
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 } ;
572
580
let ret = cvt ( unsafe {
573
581
c:: send ( * self . inner . as_inner ( ) ,
574
582
buf. as_ptr ( ) as * const c_void ,
575
583
len,
576
- 0 )
584
+ flags )
577
585
} ) ?;
578
586
Ok ( ret as usize )
579
587
}
0 commit comments