1+ #[ cfg( any(
2+ target_os = "linux" ,
3+ target_os = "android" ,
4+ target_os = "dragonfly" ,
5+ target_os = "freebsd" ,
6+ target_os = "openbsd" ,
7+ target_os = "netbsd" ,
8+ target_os = "solaris" ,
9+ target_os = "illumos" ,
10+ target_os = "haiku" ,
11+ target_os = "nto" ,
12+ target_os = "cygwin"
13+ ) ) ]
14+ use libc:: MSG_NOSIGNAL ;
15+
116use super :: { SocketAddr , sockaddr_un} ;
217#[ cfg( any( doc, target_os = "android" , target_os = "linux" ) ) ]
318use super :: { SocketAncillary , recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to} ;
@@ -13,16 +28,32 @@ use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_wi
1328 target_os = "cygwin"
1429) ) ]
1530use super :: { UCred , peer_cred} ;
16- use crate :: fmt ;
31+ use crate :: ffi :: c_void ;
1732use crate :: io:: { self , IoSlice , IoSliceMut } ;
1833use crate :: net:: Shutdown ;
1934use crate :: os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , FromRawFd , IntoRawFd , OwnedFd , RawFd } ;
2035use crate :: path:: Path ;
2136use crate :: sealed:: Sealed ;
2237use crate :: sys:: cvt;
23- use crate :: sys:: net:: Socket ;
38+ use crate :: sys:: net:: { Socket , wrlen_t } ;
2439use crate :: sys_common:: { AsInner , FromInner } ;
2540use crate :: time:: Duration ;
41+ use crate :: { cmp, fmt} ;
42+
43+ #[ cfg( not( any(
44+ target_os = "linux" ,
45+ target_os = "android" ,
46+ target_os = "dragonfly" ,
47+ target_os = "freebsd" ,
48+ target_os = "openbsd" ,
49+ target_os = "netbsd" ,
50+ target_os = "solaris" ,
51+ target_os = "illumos" ,
52+ target_os = "haiku" ,
53+ target_os = "nto" ,
54+ target_os = "cygwin"
55+ ) ) ) ]
56+ const MSG_NOSIGNAL : core:: ffi:: c_int = 0x0 ;
2657
2758/// A Unix stream socket.
2859///
@@ -633,7 +664,11 @@ impl io::Write for UnixStream {
633664#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
634665impl < ' a > io:: Write for & ' a UnixStream {
635666 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
636- self . 0 . write ( buf)
667+ let len = cmp:: min ( buf. len ( ) , <wrlen_t >:: MAX as usize ) as wrlen_t ;
668+ let ret = cvt ( unsafe {
669+ libc:: send ( self . 0 . as_raw ( ) , buf. as_ptr ( ) as * const c_void , len, MSG_NOSIGNAL )
670+ } ) ?;
671+ Ok ( ret as usize )
637672 }
638673
639674 fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
0 commit comments