From 26aeddd34e14c7d851a86ffc90211e2b68b2834c Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sun, 24 Jan 2021 19:18:12 +0100 Subject: [PATCH] Some simplifications; release v0.0.8 --- Cargo.toml | 2 +- src/bin/swayrd.rs | 15 +++------------ src/demon.rs | 26 ++++++++++++++++---------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 313d26e..9dd0fc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swayr" -version = "0.0.7" +version = "0.0.8" description = "A wofi-based LRU window-switcher for sway written in Rust" homepage = "https://git.sr.ht/~tsdh/swayr" repository = "https://git.sr.ht/~tsdh/swayr" diff --git a/src/bin/swayrd.rs b/src/bin/swayrd.rs index dff52ec..259c1bf 100644 --- a/src/bin/swayrd.rs +++ b/src/bin/swayrd.rs @@ -13,18 +13,9 @@ fn main() { Arc::new(RwLock::new(HashMap::new())); let con_props_for_ev_handler = con_props.clone(); - let subscriber_handle = thread::spawn(move || { - demon::monitor_con_events(con_props_for_ev_handler) + thread::spawn(move || { + demon::monitor_con_events(con_props_for_ev_handler); }); - match demon::serve_client_requests(con_props) { - Ok(()) => { - let subscriber_result = subscriber_handle.join(); - match subscriber_result { - Ok(()) => println!("Subscriber thread shut down cleanly."), - Err(err) => panic!(err), - } - } - Err(err) => panic!(err), - } + demon::serve_client_requests(con_props); } diff --git a/src/demon.rs b/src/demon.rs index 796e0db..0e1eb68 100644 --- a/src/demon.rs +++ b/src/demon.rs @@ -7,7 +7,6 @@ use std::os::unix::net::{UnixListener, UnixStream}; use std::process as proc; use std::sync::Arc; use std::sync::RwLock; -use std::thread; use std::time::{SystemTime, UNIX_EPOCH}; pub fn monitor_con_events( @@ -122,23 +121,30 @@ fn get_epoch_time_as_millis() -> u128 { pub fn serve_client_requests( con_props: Arc>>, -) -> std::io::Result<()> { +) { match std::fs::remove_file(util::get_swayr_socket_path()) { Ok(()) => println!("Deleted stale socket from previous run."), Err(e) => eprintln!("Could not delete socket:\n{:?}", e), } - let listener = UnixListener::bind(util::get_swayr_socket_path())?; - for stream in listener.incoming() { - match stream { - Ok(stream) => { - let wp_clone = con_props.clone(); - thread::spawn(move || handle_client_request(stream, wp_clone)); + match UnixListener::bind(util::get_swayr_socket_path()) { + Ok(listener) => { + for stream in listener.incoming() { + match stream { + Ok(stream) => { + handle_client_request(stream, con_props.clone()); + } + Err(err) => { + eprintln!("Error handling client request: {}", err); + break; + } + } } - Err(err) => return Err(err), + } + Err(err) => { + eprintln!("Could not bind socket: {}", err) } } - Ok(()) } fn handle_client_request(