File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ use libc::SOCK_CLOEXEC;
33
33
#[ cfg( not( target_os = "linux" ) ) ]
34
34
const SOCK_CLOEXEC : c_int = 0 ;
35
35
36
+ // Another conditional contant for name resolution: Macos et iOS use
37
+ // SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket.
38
+ // Other platforms do otherwise.
39
+ #[ cfg( target_vendor = "apple" ) ]
40
+ use libc:: SO_NOSIGPIPE ;
41
+ #[ cfg( not( target_vendor = "apple" ) ) ]
42
+ const SO_NOSIGPIPE : c_int = 0 ;
43
+
36
44
pub struct Socket ( FileDesc ) ;
37
45
38
46
pub fn init ( ) { }
@@ -81,7 +89,11 @@ impl Socket {
81
89
let fd = cvt ( libc:: socket ( fam, ty, 0 ) ) ?;
82
90
let fd = FileDesc :: new ( fd) ;
83
91
fd. set_cloexec ( ) ?;
84
- Ok ( Socket ( fd) )
92
+ let socket = Socket ( fd) ;
93
+ if cfg ! ( target_vendor = "apple" ) {
94
+ setsockopt ( & socket, libc:: SOL_SOCKET , SO_NOSIGPIPE , 1 ) ?;
95
+ }
96
+ Ok ( socket)
85
97
}
86
98
}
87
99
You can’t perform that action at this time.
0 commit comments