pub trait ShareHandle: AsRawHandle {
// Provided method
fn share(&self, reciever: *mut c_void) -> Result<*mut c_void> { ... }
}Expand description
Objects which own handles which can be shared with another processes.
On Windows, like with most other operating systems, handles belong to specific processes. You shouldn’t just send the value of a handle to another process (with a named pipe, for example) and expect it to work on the other side. For this to work, you need DuplicateHandle – the Win32 API function which duplicates a handle into the handle table of the specified process (the reciever is referred to by its handle). This trait exposes the DuplicateHandle functionality in a safe manner. If the handle is inheritable, however, all child processes of a process inherit the handle and thus can use the same value safely without the need to share it. All Windows handle objects created by this crate are inheritable.
Implemented for all types inside this crate which implement AsRawHandle and are supposed to be shared between processes.
Provided Methods§
Duplicates the handle to make it accessible in the specified process (taken as a handle to that process) and returns the raw value of the handle which can then be sent via some form of IPC, typically named pipes. This is the only way to use any form of IPC other than named pipes to communicate between two processes which do not have a parent-child relationship or if the handle wasn’t created as inheritable, therefore named pipes paired with this are a hard requirement in order to communicate between processes if one wasn’t spawned by another.
Backed by [DuplicateHandle]. Doesn’t require unsafe code since DuplicateHandle never leads to undefined behavior if the lpTargetHandle parameter is a valid pointer, only creates an error.