@@ -74,6 +74,7 @@ impl Socket {
74
74
if #[ cfg( any(
75
75
target_os = "android" ,
76
76
target_os = "dragonfly" ,
77
+ target_os = "freebsd" ,
77
78
target_os = "illumos" ,
78
79
target_os = "hurd" ,
79
80
target_os = "linux" ,
@@ -85,16 +86,22 @@ impl Socket {
85
86
// flag to atomically create the socket and set it as
86
87
// CLOEXEC. On Linux this was added in 2.6.27.
87
88
let fd = cvt( libc:: socket( fam, ty | libc:: SOCK_CLOEXEC , 0 ) ) ?;
88
- Ok ( Socket ( FileDesc :: from_raw_fd( fd) ) )
89
+ let socket = Socket ( FileDesc :: from_raw_fd( fd) ) ;
90
+
91
+ // DragonFlyBSD, FreeBSD and NetBSD use `SO_NOSIGPIPE` as a `setsockopt`
92
+ // flag to disable `SIGPIPE` emission on socket.
93
+ #[ cfg( any( target_os = "dragonfly" , target_os = "freebsd" , target_os = "netbsd" ) ) ]
94
+ setsockopt( & socket, libc:: SOL_SOCKET , libc:: SO_NOSIGPIPE , 1 ) ?;
95
+ Ok ( socket)
89
96
} else {
90
97
let fd = cvt( libc:: socket( fam, ty, 0 ) ) ?;
91
98
let fd = FileDesc :: from_raw_fd( fd) ;
92
99
fd. set_cloexec( ) ?;
93
100
let socket = Socket ( fd) ;
94
101
95
- // macOS, iOS and FreeBSD use `SO_NOSIGPIPE` as a `setsockopt`
102
+ // macOS and iOS use `SO_NOSIGPIPE` as a `setsockopt`
96
103
// flag to disable `SIGPIPE` emission on socket.
97
- #[ cfg( any ( target_vendor = "apple" , target_os = "freebsd" ) ) ]
104
+ #[ cfg( target_vendor = "apple" ) ]
98
105
setsockopt( & socket, libc:: SOL_SOCKET , libc:: SO_NOSIGPIPE , 1 ) ?;
99
106
100
107
Ok ( socket)
0 commit comments