diff options
| author | Eskil Queseth <eskilq@kth.se> | 2021-03-24 21:38:51 +0100 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2021-03-24 21:38:51 +0100 |
| commit | d484c05e56194346944b295968c66ccc0e543534 (patch) | |
| tree | 41ee9fba2ad0841bffbd04b805ae6d675be7fb52 /mumctl | |
| parent | a5c26eaad44c45da852027d707bf1d8e838ed901 (diff) | |
| download | mum-d484c05e56194346944b295968c66ccc0e543534.tar.gz | |
remove ipc-channel dependency
Diffstat (limited to 'mumctl')
| -rw-r--r-- | mumctl/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 19 |
2 files changed, 11 insertions, 10 deletions
diff --git a/mumctl/Cargo.toml b/mumctl/Cargo.toml index b22ca02..02326c8 100644 --- a/mumctl/Cargo.toml +++ b/mumctl/Cargo.toml @@ -16,6 +16,6 @@ mumlib = { version = "0.3", path = "../mumlib" } clap = { version = "2.33", features = ["yaml"] } colored = "2.0" log = "0.4" -ipc-channel = "0.15" +bincode = "1.3.2" #cursive = "0.15" diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index d07a482..3cbbcf7 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,15 +1,15 @@ use clap::{App, AppSettings, Arg, Shell, SubCommand, ArgMatches}; use colored::Colorize; -use ipc_channel::ipc::{self, IpcSender}; use log::{error, warn}; use log::{Record, Level, Metadata, LevelFilter}; use mumlib::command::{Command, CommandResponse}; use mumlib::config; use mumlib::config::{ServerConfig, Config}; use mumlib::state::Channel; -use std::io::BufRead; -use std::{fs, io, iter, fmt}; +use std::io::{BufRead, Write}; +use std::{io::{self, Read}, iter, fmt}; use std::fmt::{Display, Formatter}; +use std::os::unix::net::UnixStream; const INDENTATION: &str = " "; @@ -615,16 +615,17 @@ fn parse_status(server_state: &mumlib::state::Server) { } fn send_command(command: Command) -> Result<mumlib::error::Result<Option<CommandResponse>>, crate::Error> { - let (tx_client, rx_client) = - ipc::channel::<mumlib::error::Result<Option<CommandResponse>>>().unwrap(); + let mut connection = UnixStream::connect("/tmp/mumd").unwrap(); - let server_name = fs::read_to_string(mumlib::SOCKET_PATH).unwrap(); //TODO don't panic + let serialized = bincode::serialize(&command).unwrap(); - let tx0 = IpcSender::connect(server_name).map_err(|_| Error::ConnectionError)?; + connection.write(&(serialized.len() as u32).to_be_bytes()).unwrap(); + connection.write(&serialized).unwrap(); - tx0.send((command, tx_client)).unwrap(); + connection.read_exact(&mut [0; 4]).unwrap(); + let response = bincode::deserialize_from(&mut connection).unwrap(); - Ok(rx_client.recv().unwrap()) + Ok(response) } fn print_channel(channel: &Channel, depth: usize) { |
