File tree 1 file changed +34
-1
lines changed
library/std/src/os/unix/net
1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,35 @@ use crate::sys::cvt;
23
23
use crate :: sys:: net:: Socket ;
24
24
use crate :: sys_common:: { AsInner , FromInner } ;
25
25
use crate :: time:: Duration ;
26
+ use crate :: cmp;
27
+ #[ cfg( any(
28
+ target_os = "linux" ,
29
+ target_os = "android" ,
30
+ target_os = "dragonfly" ,
31
+ target_os = "freebsd" ,
32
+ target_os = "openbsd" ,
33
+ target_os = "netbsd" ,
34
+ target_os = "solaris" ,
35
+ target_os = "illumos" ,
36
+ target_os = "haiku" ,
37
+ target_os = "nto" ,
38
+ target_os = "cygwin"
39
+ ) ) ]
40
+ use libc:: MSG_NOSIGNAL ;
41
+ #[ cfg( not( any(
42
+ target_os = "linux" ,
43
+ target_os = "android" ,
44
+ target_os = "dragonfly" ,
45
+ target_os = "freebsd" ,
46
+ target_os = "openbsd" ,
47
+ target_os = "netbsd" ,
48
+ target_os = "solaris" ,
49
+ target_os = "illumos" ,
50
+ target_os = "haiku" ,
51
+ target_os = "nto" ,
52
+ target_os = "cygwin"
53
+ ) ) ) ]
54
+ const MSG_NOSIGNAL : core:: ffi:: c_int = 0x0 ;
26
55
27
56
/// A Unix stream socket.
28
57
///
@@ -633,7 +662,11 @@ impl io::Write for UnixStream {
633
662
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
634
663
impl < ' a > io:: Write for & ' a UnixStream {
635
664
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
636
- self . 0 . write ( buf)
665
+ let len = cmp:: min ( buf. len ( ) , <wrlen_t >:: MAX as usize ) as wrlen_t ;
666
+ let ret = cvt ( unsafe {
667
+ c:: send ( self . 0 . as_raw ( ) , buf. as_ptr ( ) as * const c_void , len, MSG_NOSIGNAL )
668
+ } ) ?;
669
+ Ok ( ret as usize )
637
670
}
638
671
639
672
fn write_vectored ( & mut self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
You can’t perform that action at this time.
0 commit comments