1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//{
use std::{io, os};
#[cfg(windows)]
type Handle = os::windows::io::OwnedHandle;
#[cfg(unix)]
type Handle = os::unix::io::OwnedFd;
pub(crate) async fn emain(handle: Handle) -> io::Result<()> {
//}
use {interprocess::unnamed_pipe, tokio::io::AsyncWriteExt};
// `handle` here is an `OwnedHandle` or an `OwnedFd` from the standard library. Those
// implement `FromRawHandle` and `FromRawFd` respectively. The actual value can be transferred
// via a command-line parameter since it's numerically equal to the value obtained in the
// parent process via `OwnedHandle::try_from()`/`OwnedFd::try_from()` thanks to handle
// inheritance.
let mut tx = unnamed_pipe::tokio::Sender::try_from(handle)?;
// Send our message to the other side.
tx.write_all(b"Hello from side B!\n").await?;
//{
Ok(())
}
#[allow(dead_code)]
fn main() {} //}
|