diff options
Diffstat (limited to 'src/socket.rs')
-rw-r--r-- | src/socket.rs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/socket.rs b/src/socket.rs deleted file mode 100644 index b3bb9cc..0000000 --- a/src/socket.rs +++ /dev/null @@ -1,63 +0,0 @@ -// See LICENSE file for copyright and license details. - -use std::io::{Read,Write}; -use std::sync::mpsc::{Receiver, TryRecvError}; - -use unix_socket::UnixStream; - -use dotwm::DotWM; -use command::*; - -#[allow(unused_variables)] -fn handle_socket(dotwm: &mut DotWM, stream: UnixStream) { - let mut s = stream.try_clone().unwrap(); - let mut buf = String::new(); - s.read_to_string(&mut buf).unwrap(); - println!("buf: {}", buf); - - let _ = write!(s, "ok"); -} - -#[allow(unused_variables)] -/// Handles the configuration and returns true when we're finished. -fn handle_configure(dotwm: &mut DotWM, s: UnixStream) -> bool { - let mut stream = match s.try_clone() { - Ok(s) => s, - Err(_) => { println!("Error"); return true }, - }; - - let mut input = String::new(); - stream.read_to_string(&mut input).unwrap(); - - if input != "done" { - let _ = write!(stream, "ok"); - false - } else { - let _ = write!(stream, "exit"); - true - } -} - -pub fn configure_wm(dotwm: &mut DotWM, rx: &Receiver<UnixStream>) { - exec_cmd("./autostart", &[]).unwrap(); - loop { - match rx.recv() { - Ok(stream) => { - if handle_configure(dotwm, stream) { - break; - } - }, - Err(e) => panic!("Socket: {}", e), - } - } -} - -pub fn listen_socket(dotwm: &mut DotWM, rx: &Receiver<UnixStream>) { - loop { - match rx.try_recv() { - Ok(stream) => handle_socket(dotwm, stream) , - Err(TryRecvError::Empty) => break, - Err(TryRecvError::Disconnected) => panic!("Socket disconnected"), - } - } -} |