@@ -18,16 +18,6 @@ pub extern crate libc as netc;
18
18
19
19
pub type wrlen_t = size_t ;
20
20
21
- // See below for the usage of SOCK_CLOEXEC, but this constant is only defined on
22
- // Linux currently (e.g., support doesn't exist on other platforms). In order to
23
- // get name resolution to work and things to compile we just define a dummy
24
- // SOCK_CLOEXEC here for other platforms. Note that the dummy constant isn't
25
- // actually ever used (the blocks below are wrapped in `if cfg!` as well.
26
- #[ cfg( target_os = "linux" ) ]
27
- use libc:: SOCK_CLOEXEC ;
28
- #[ cfg( not( target_os = "linux" ) ) ]
29
- const SOCK_CLOEXEC : c_int = 0 ;
30
-
31
21
pub struct Socket ( FileDesc ) ;
32
22
33
23
pub fn init ( ) { }
@@ -69,8 +59,9 @@ impl Socket {
69
59
// this option, however, was added in 2.6.27, and we still support
70
60
// 2.6.18 as a kernel, so if the returned error is EINVAL we
71
61
// fallthrough to the fallback.
72
- if cfg ! ( target_os = "linux" ) {
73
- match cvt ( libc:: socket ( fam, ty | SOCK_CLOEXEC , 0 ) ) {
62
+ #[ cfg( target_os = "linux" ) ]
63
+ {
64
+ match cvt ( libc:: socket ( fam, ty | libc:: SOCK_CLOEXEC , 0 ) ) {
74
65
Ok ( fd) => return Ok ( Socket ( FileDesc :: new ( fd) ) ) ,
75
66
Err ( ref e) if e. raw_os_error ( ) == Some ( libc:: EINVAL ) => { }
76
67
Err ( e) => return Err ( e) ,
@@ -96,8 +87,9 @@ impl Socket {
96
87
let mut fds = [ 0 , 0 ] ;
97
88
98
89
// Like above, see if we can set cloexec atomically
99
- if cfg ! ( target_os = "linux" ) {
100
- match cvt ( libc:: socketpair ( fam, ty | SOCK_CLOEXEC , 0 , fds. as_mut_ptr ( ) ) ) {
90
+ #[ cfg( target_os = "linux" ) ]
91
+ {
92
+ match cvt ( libc:: socketpair ( fam, ty | libc:: SOCK_CLOEXEC , 0 , fds. as_mut_ptr ( ) ) ) {
101
93
Ok ( _) => {
102
94
return Ok ( ( Socket ( FileDesc :: new ( fds[ 0 ] ) ) , Socket ( FileDesc :: new ( fds[ 1 ] ) ) ) ) ;
103
95
}
@@ -187,7 +179,8 @@ impl Socket {
187
179
// atomically set the CLOEXEC flag is to use the `accept4` syscall on
188
180
// Linux. This was added in 2.6.28, however, and because we support
189
181
// 2.6.18 we must detect this support dynamically.
190
- if cfg ! ( target_os = "linux" ) {
182
+ #[ cfg( target_os = "linux" ) ]
183
+ {
191
184
syscall ! {
192
185
fn accept4(
193
186
fd: c_int,
@@ -196,7 +189,7 @@ impl Socket {
196
189
flags: c_int
197
190
) -> c_int
198
191
}
199
- let res = cvt_r ( || unsafe { accept4 ( self . 0 . raw ( ) , storage, len, SOCK_CLOEXEC ) } ) ;
192
+ let res = cvt_r ( || unsafe { accept4 ( self . 0 . raw ( ) , storage, len, libc :: SOCK_CLOEXEC ) } ) ;
200
193
match res {
201
194
Ok ( fd) => return Ok ( Socket ( FileDesc :: new ( fd) ) ) ,
202
195
Err ( ref e) if e. raw_os_error ( ) == Some ( libc:: ENOSYS ) => { }
0 commit comments