File: side_b.rs

package info (click to toggle)
rust-interprocess 2.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,016 kB
  • sloc: makefile: 2
file content (24 lines) | stat: -rw-r--r-- 879 bytes parent folder | download
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() {} //}