Separated orchid-host and orchid-extension

This is an architectural change that allows me to implment specifics first and generalize along observed symmetries in orchid-base
This commit is contained in:
2024-05-01 21:20:17 +02:00
parent aa3f7e99ab
commit bc3b10674b
25 changed files with 562 additions and 357 deletions

28
orchid-host/src/child.rs Normal file
View File

@@ -0,0 +1,28 @@
use std::io;
use std::sync::Mutex;
use std::{mem, process};
use orchid_base::msg::{recv_msg, send_msg};
pub struct SharedChild {
child: process::Child,
stdin: Mutex<process::ChildStdin>,
stdout: Mutex<process::ChildStdout>,
}
impl SharedChild {
pub fn new(cmd: &mut process::Command) -> io::Result<Self> {
let mut child = cmd.stdin(process::Stdio::piped()).stdout(process::Stdio::piped()).spawn()?;
let stdin = Mutex::new(child.stdin.take().expect("Piped stdin above"));
let stdout = Mutex::new(child.stdout.take().expect("Piped stdout above"));
Ok(Self { stdin, stdout, child })
}
pub fn send_msg(&self, msg: &[u8]) -> io::Result<()> {
send_msg(&mut *self.stdin.lock().unwrap(), msg)
}
pub fn recv_msg(&self) -> io::Result<Vec<u8>> { recv_msg(&mut *self.stdout.lock().unwrap()) }
}
impl Drop for SharedChild {
fn drop(&mut self) { mem::drop(self.child.kill()) }
}