mirror of
https://github.com/ParkerTenBroeck/hdl_sim.git
synced 2026-06-07 05:28:45 -04:00
removed silly thing
This commit is contained in:
parent
0201990df8
commit
04c3d69cbf
2 changed files with 12 additions and 14 deletions
|
|
@ -72,15 +72,15 @@ async fn ws_handler(socket: WebSocket) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let (_process, mut sin, sout, serr) = match run::run(&artifact_dir).await{
|
let mut process = match run::run(&artifact_dir).await{
|
||||||
Ok(process) => process,
|
Ok(process) => process,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
_ = sender.send(Message::Text(format!("Failed to run: {err}").into())).await;
|
_ = sender.send(Message::Text(format!("Failed to run: {err}").into())).await;
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let mut sout = BufReader::new(sout).lines();
|
let mut sout = BufReader::new(process.stdout).lines();
|
||||||
let mut serr = BufReader::new(serr).lines();
|
let mut serr = BufReader::new(process.stderr).lines();
|
||||||
|
|
||||||
let artifact_prefix = artifact_dir.to_str().unwrap_or("\0\0NOPE");
|
let artifact_prefix = artifact_dir.to_str().unwrap_or("\0\0NOPE");
|
||||||
|
|
||||||
|
|
@ -93,8 +93,8 @@ async fn ws_handler(socket: WebSocket) {
|
||||||
Some(Ok(Message::Text(msg))) => {
|
Some(Ok(Message::Text(msg))) => {
|
||||||
let input = serde_json::from_str::<'_, ClientInput>(&msg)?;
|
let input = serde_json::from_str::<'_, ClientInput>(&msg)?;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
sin.write_all(format!("key={}\n", input.buttons).as_bytes()).await?;
|
process.stdin.write_all(format!("key={}\n", input.buttons).as_bytes()).await?;
|
||||||
sin.write_all(format!("sw={}\n", input.switch).as_bytes()).await?;
|
process.stdin.write_all(format!("sw={}\n", input.switch).as_bytes()).await?;
|
||||||
},
|
},
|
||||||
Some(Ok(_)) => {},
|
Some(Ok(_)) => {},
|
||||||
Some(Err(err)) => Err(err)?,
|
Some(Err(err)) => Err(err)?,
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,17 @@ use std::{path::Path};
|
||||||
use tokio::process::{Child, ChildStdin, ChildStdout, ChildStderr, Command};
|
use tokio::process::{Child, ChildStdin, ChildStdout, ChildStderr, Command};
|
||||||
|
|
||||||
pub struct Process{
|
pub struct Process{
|
||||||
child: Child,
|
pub child: Child,
|
||||||
|
pub stdin: ChildStdin,
|
||||||
|
pub stdout: ChildStdout,
|
||||||
|
pub stderr: ChildStderr
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Process{
|
pub async fn run(artifact_dir: &Path) -> Result<Process, Box<dyn std::error::Error + Send + Sync>>{
|
||||||
fn drop(&mut self) {
|
|
||||||
_ = self.child.start_kill()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run(artifact_dir: &Path) -> Result<(Process, ChildStdin, ChildStdout, ChildStderr), Box<dyn std::error::Error + Send + Sync>>{
|
|
||||||
let mut cmd = Command::new("ghdl");
|
let mut cmd = Command::new("ghdl");
|
||||||
cmd.args(["-r", "--std=08", "tb", "--stop-delta=2147483647", "--unbuffered"]);
|
cmd.args(["-r", "--std=08", "tb", "--stop-delta=2147483647", "--unbuffered"]);
|
||||||
cmd.current_dir(artifact_dir);
|
cmd.current_dir(artifact_dir);
|
||||||
|
cmd.kill_on_drop(true);
|
||||||
|
|
||||||
cmd.stdin(std::process::Stdio::piped())
|
cmd.stdin(std::process::Stdio::piped())
|
||||||
.stdout(std::process::Stdio::piped())
|
.stdout(std::process::Stdio::piped())
|
||||||
|
|
@ -27,5 +25,5 @@ pub async fn run(artifact_dir: &Path) -> Result<(Process, ChildStdin, ChildStdo
|
||||||
let stdout = child.stdout.take().ok_or("no stdout")?;
|
let stdout = child.stdout.take().ok_or("no stdout")?;
|
||||||
let stderr = child.stderr.take().ok_or("no stderr")?;
|
let stderr = child.stderr.take().ok_or("no stderr")?;
|
||||||
|
|
||||||
Ok((Process { child }, stdin, stdout, stderr))
|
Ok(Process { child, stdin, stdout, stderr })
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue