File tree 1 file changed +17
-2
lines changed
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -144,11 +144,24 @@ impl FileDesc {
144
144
pub fn set_cloexec ( & self ) -> io:: Result < ( ) > {
145
145
unsafe {
146
146
let previous = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFD ) ) ?;
147
- cvt ( libc:: fcntl ( self . fd , libc:: F_SETFD , previous | libc:: FD_CLOEXEC ) ) ?;
147
+ let new = previous | libc:: FD_CLOEXEC ;
148
+ if new != previous {
149
+ cvt ( libc:: fcntl ( self . fd , libc:: F_SETFD , new) ) ?;
150
+ }
151
+ Ok ( ( ) )
152
+ }
153
+ }
154
+
155
+ #[ cfg( target_os = "linux" ) ]
156
+ pub fn set_nonblocking ( & self , nonblocking : bool ) -> io:: Result < ( ) > {
157
+ unsafe {
158
+ let v = nonblocking as c_int ;
159
+ cvt ( libc:: ioctl ( self . fd , libc:: FIONBIO , & v) ) ?;
148
160
Ok ( ( ) )
149
161
}
150
162
}
151
163
164
+ #[ cfg( not( target_os = "linux" ) ) ]
152
165
pub fn set_nonblocking ( & self , nonblocking : bool ) -> io:: Result < ( ) > {
153
166
unsafe {
154
167
let previous = cvt ( libc:: fcntl ( self . fd , libc:: F_GETFL ) ) ?;
@@ -157,7 +170,9 @@ impl FileDesc {
157
170
} else {
158
171
previous & !libc:: O_NONBLOCK
159
172
} ;
160
- cvt ( libc:: fcntl ( self . fd , libc:: F_SETFL , new) ) ?;
173
+ if new != previous {
174
+ cvt ( libc:: fcntl ( self . fd , libc:: F_SETFL , new) ) ?;
175
+ }
161
176
Ok ( ( ) )
162
177
}
163
178
}
You can’t perform that action at this time.
0 commit comments