Add set_inheritable for Windows Handles

This commit is contained in:
Chris Denton 2022-04-26 15:56:26 +01:00
parent 7417110cef
commit b89b056742
No known key found for this signature in database
GPG key ID: 713472F2F45627DE
2 changed files with 16 additions and 0 deletions

View file

@ -198,6 +198,18 @@ impl OwnedHandle {
})?;
unsafe { Ok(Self::from_raw_handle(ret)) }
}
/// Allow child processes to inherit the handle.
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
cvt(unsafe {
c::SetHandleInformation(
self.as_raw_handle(),
c::HANDLE_FLAG_INHERIT,
c::HANDLE_FLAG_INHERIT,
)
})?;
Ok(())
}
}
impl TryFrom<HandleOrInvalid> for OwnedHandle {

View file

@ -221,6 +221,10 @@ impl Handle {
Ok(Self(self.0.duplicate(access, inherit, options)?))
}
pub(crate) fn set_inheritable(&self) -> io::Result<()> {
self.0.set_inheritable()
}
/// Performs a synchronous read.
///
/// If the handle is opened for asynchronous I/O then this abort the process.