@@ -15,7 +15,6 @@ use io;
15
15
use libc:: { self , c_int, size_t} ;
16
16
use net:: { SocketAddr , Shutdown } ;
17
17
use str;
18
- use sync:: atomic:: { AtomicBool , Ordering } ;
19
18
use sys:: fd:: FileDesc ;
20
19
use sys_common:: { AsInner , FromInner , IntoInner } ;
21
20
use sys_common:: net:: { getsockopt, setsockopt} ;
@@ -67,44 +66,7 @@ impl Socket {
67
66
}
68
67
69
68
pub fn duplicate ( & self ) -> io:: Result < Socket > {
70
- // We want to atomically duplicate this file descriptor and set the
71
- // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
72
- // flag, however, isn't supported on older Linux kernels (earlier than
73
- // 2.6.24).
74
- //
75
- // To detect this and ensure that CLOEXEC is still set, we
76
- // follow a strategy similar to musl [1] where if passing
77
- // F_DUPFD_CLOEXEC causes `fcntl` to return EINVAL it means it's not
78
- // supported (the third parameter, 0, is always valid), so we stop
79
- // trying that. We also *still* call the `set_cloexec` method as
80
- // apparently some kernel at some point stopped setting CLOEXEC even
81
- // though it reported doing so on F_DUPFD_CLOEXEC.
82
- //
83
- // Also note that Android doesn't have F_DUPFD_CLOEXEC, but get it to
84
- // resolve so we at least compile this.
85
- //
86
- // [1]: http://comments.gmane.org/gmane.linux.lib.musl.general/2963
87
- #[ cfg( target_os = "android" ) ]
88
- use libc:: F_DUPFD as F_DUPFD_CLOEXEC ;
89
- #[ cfg( not( target_os = "android" ) ) ]
90
- use libc:: F_DUPFD_CLOEXEC ;
91
-
92
- let make_socket = |fd| {
93
- let fd = FileDesc :: new ( fd) ;
94
- fd. set_cloexec ( ) ;
95
- Socket ( fd)
96
- } ;
97
- static TRY_CLOEXEC : AtomicBool = AtomicBool :: new ( true ) ;
98
- let fd = self . 0 . raw ( ) ;
99
- if !cfg ! ( target_os = "android" ) && TRY_CLOEXEC . load ( Ordering :: Relaxed ) {
100
- match cvt ( unsafe { libc:: fcntl ( fd, F_DUPFD_CLOEXEC , 0 ) } ) {
101
- Err ( ref e) if e. raw_os_error ( ) == Some ( libc:: EINVAL ) => {
102
- TRY_CLOEXEC . store ( false , Ordering :: Relaxed ) ;
103
- }
104
- res => return res. map ( make_socket) ,
105
- }
106
- }
107
- cvt ( unsafe { libc:: fcntl ( fd, libc:: F_DUPFD , 0 ) } ) . map ( make_socket)
69
+ self . 0 . duplicate ( ) . map ( Socket )
108
70
}
109
71
110
72
pub fn read ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
0 commit comments