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
+
1
16
use super :: { SocketAddr , sockaddr_un} ;
2
17
#[ cfg( any( doc, target_os = "android" , target_os = "linux" ) ) ]
3
18
use 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
13
28
target_os = "cygwin"
14
29
) ) ]
15
30
use super :: { UCred , peer_cred} ;
16
- use crate :: fmt ;
31
+ use crate :: ffi :: c_void ;
17
32
use crate :: io:: { self , IoSlice , IoSliceMut } ;
18
33
use crate :: net:: Shutdown ;
19
34
use crate :: os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , FromRawFd , IntoRawFd , OwnedFd , RawFd } ;
20
35
use crate :: path:: Path ;
21
36
use crate :: sealed:: Sealed ;
22
37
use crate :: sys:: cvt;
23
- use crate :: sys:: net:: Socket ;
38
+ use crate :: sys:: net:: { Socket , wrlen_t } ;
24
39
use crate :: sys_common:: { AsInner , FromInner } ;
25
40
use 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 ;
26
57
27
58
/// A Unix stream socket.
28
59
///
@@ -633,7 +664,11 @@ impl io::Write for UnixStream {
633
664
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
634
665
impl < ' a > io:: Write for & ' a UnixStream {
635
666
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 )
637
672
}
638
673
639
674
fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
0 commit comments