Basic IPC testing
This commit is contained in:
parent
2c269e78b6
commit
ba740808f1
4 changed files with 62 additions and 2 deletions
|
@ -1 +1,17 @@
|
||||||
fn main() {}
|
use std::io::Write;
|
||||||
|
|
||||||
|
use deerwm::commands;
|
||||||
|
use nanoserde::SerBin;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut cmd_fifo = unix_named_pipe::open_write(commands::DEFAULT_PIPE)
|
||||||
|
.expect("failed to open fifo for writing");
|
||||||
|
|
||||||
|
let quit_cmd = commands::Command::Quit;
|
||||||
|
let mut cmd_buffer = Vec::new();
|
||||||
|
quit_cmd.ser_bin(&mut cmd_buffer);
|
||||||
|
|
||||||
|
cmd_fifo
|
||||||
|
.write_all(&cmd_buffer[..])
|
||||||
|
.expect("failed to write to fifo");
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,36 @@
|
||||||
fn main() {}
|
use commands::Command;
|
||||||
|
use nanoserde::DeBin;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use deerwm::commands;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if let Err(e) = unix_named_pipe::create(commands::DEFAULT_PIPE, None) {
|
||||||
|
match e.kind() {
|
||||||
|
std::io::ErrorKind::AlreadyExists => {}
|
||||||
|
_ => panic!("{}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut cmd_fifo =
|
||||||
|
unix_named_pipe::open_read(commands::DEFAULT_PIPE).expect("failed to open fifo");
|
||||||
|
let mut cmd_buffer = [0; 256];
|
||||||
|
|
||||||
|
'run: loop {
|
||||||
|
if let Ok(n) = cmd_fifo.read(&mut cmd_buffer) {
|
||||||
|
if n > 0 {
|
||||||
|
println!("{:?}", &cmd_buffer[..n]);
|
||||||
|
|
||||||
|
if let Ok(cmd) = Command::de_bin(&mut 0, &cmd_buffer[..n]) {
|
||||||
|
match cmd {
|
||||||
|
Command::Quit => {
|
||||||
|
println!("Recieved quit command!");
|
||||||
|
break 'run;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::fs::remove_file(commands::DEFAULT_PIPE).expect("failed to create fifo");
|
||||||
|
}
|
||||||
|
|
8
src/commands.rs
Normal file
8
src/commands.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
use nanoserde::{DeBin, SerBin};
|
||||||
|
|
||||||
|
pub const DEFAULT_PIPE: &str = "/tmp/deerwm";
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, DeBin, SerBin)]
|
||||||
|
pub enum Command {
|
||||||
|
Quit
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod commands;
|
Loading…
Reference in a new issue