diff options
Diffstat (limited to 'mumctl')
| -rw-r--r-- | mumctl/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 26 |
2 files changed, 11 insertions, 17 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 65dac61..45ee126 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,15 +1,10 @@ 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 log::{Record, Level, Metadata, LevelFilter, error, warn}; use mumlib::command::{Command, CommandResponse}; -use mumlib::config; -use mumlib::config::{ServerConfig, Config}; +use mumlib::config::{self, ServerConfig, Config}; use mumlib::state::Channel; -use std::io::BufRead; -use std::{fs, io, iter, fmt}; -use std::fmt::{Display, Formatter}; +use std::{io::{self, Read, BufRead, Write}, iter, fmt::{Display, Formatter}, os::unix::net::UnixStream}; const INDENTATION: &str = " "; @@ -622,16 +617,15 @@ 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(mumlib::SOCKET_PATH).map_err(|_| Error::ConnectionError)?; - 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()).map_err(|_| Error::ConnectionError)?; + connection.write(&serialized).map_err(|_| Error::ConnectionError)?; - tx0.send((command, tx_client)).unwrap(); - - Ok(rx_client.recv().unwrap()) + connection.read_exact(&mut [0; 4]).map_err(|_| Error::ConnectionError)?; + bincode::deserialize_from(&mut connection).map_err(|_| Error::ConnectionError) } fn print_channel(channel: &Channel, depth: usize) { @@ -665,7 +659,7 @@ enum Error { } impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "Unable to connect to mumd. Is mumd running?") } } |
