Skip to content

Commit 0c002e8

Browse files
committed
Put Socket::set_no_inherit behind the all feature
1 parent 053735f commit 0c002e8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/sys/windows.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ use winapi::ctypes::{c_char, c_ulong};
2222
use winapi::shared::in6addr::*;
2323
use winapi::shared::inaddr::*;
2424
use winapi::shared::minwindef::DWORD;
25+
#[cfg(feature = "all")]
2526
use winapi::shared::ntdef::HANDLE;
2627
use winapi::shared::ws2def::{self, *};
2728
use winapi::shared::ws2ipdef::*;
29+
#[cfg(feature = "all")]
2830
use winapi::um::handleapi::SetHandleInformation;
2931
use winapi::um::processthreadsapi::GetCurrentProcessId;
32+
#[cfg(feature = "all")]
33+
use winapi::um::winbase;
3034
use winapi::um::winbase::INFINITE;
3135
use winapi::um::winsock2 as sock;
3236

@@ -205,12 +209,18 @@ pub(crate) fn getpeername(socket: SysSocket) -> io::Result<SockAddr> {
205209
.map(|_| unsafe { SockAddr::from_raw_parts(&storage as *const _ as *const _, len) })
206210
}
207211

212+
/// Windows only API.
208213
impl crate::Socket {
209214
/// Sets `HANDLE_FLAG_INHERIT` to zero using `SetHandleInformation`.
215+
#[cfg(feature = "all")]
210216
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())
214224
} else {
215225
Ok(())
216226
}

0 commit comments

Comments
 (0)