@@ -22,11 +22,15 @@ use winapi::ctypes::{c_char, c_ulong};
22
22
use winapi:: shared:: in6addr:: * ;
23
23
use winapi:: shared:: inaddr:: * ;
24
24
use winapi:: shared:: minwindef:: DWORD ;
25
+ #[ cfg( feature = "all" ) ]
25
26
use winapi:: shared:: ntdef:: HANDLE ;
26
27
use winapi:: shared:: ws2def:: { self , * } ;
27
28
use winapi:: shared:: ws2ipdef:: * ;
29
+ #[ cfg( feature = "all" ) ]
28
30
use winapi:: um:: handleapi:: SetHandleInformation ;
29
31
use winapi:: um:: processthreadsapi:: GetCurrentProcessId ;
32
+ #[ cfg( feature = "all" ) ]
33
+ use winapi:: um:: winbase;
30
34
use winapi:: um:: winbase:: INFINITE ;
31
35
use winapi:: um:: winsock2 as sock;
32
36
@@ -205,12 +209,18 @@ pub(crate) fn getpeername(socket: SysSocket) -> io::Result<SockAddr> {
205
209
. map ( |_| unsafe { SockAddr :: from_raw_parts ( & storage as * const _ as * const _ , len) } )
206
210
}
207
211
212
+ /// Windows only API.
208
213
impl crate :: Socket {
209
214
/// Sets `HANDLE_FLAG_INHERIT` to zero using `SetHandleInformation`.
215
+ #[ cfg( feature = "all" ) ]
210
216
pub fn set_no_inherit ( & self ) -> io:: Result < ( ) > {
211
- let r = unsafe { SetHandleInformation ( self . inner as HANDLE , HANDLE_FLAG_INHERIT , 0 ) } ;
212
- if r == 0 {
213
- Err ( last_error ( ) )
217
+ // NOTE: can't use `syscall!` because it expects the function in the
218
+ // `sock::` path.
219
+ let res =
220
+ unsafe { SetHandleInformation ( self . inner as HANDLE , winbase:: HANDLE_FLAG_INHERIT , 0 ) } ;
221
+ if res == 0 {
222
+ // Zero means error.
223
+ Err ( io:: Error :: last_os_error ( ) )
214
224
} else {
215
225
Ok ( ( ) )
216
226
}
0 commit comments