diff --git a/src/bin/ptth_server.rs b/src/bin/ptth_server.rs index 3d972c1..1577ae0 100644 --- a/src/bin/ptth_server.rs +++ b/src/bin/ptth_server.rs @@ -27,11 +27,5 @@ async fn main () -> Result <(), Box > { toml::from_str (&config_s).expect (&format! ("Can't parse {:?} as TOML", config_file_path)) }; - let opt = Opt::from_args (); - - let opt = ptth::server::Opt { - - }; - - ptth::server::main (config_file, opt).await + ptth::server::main (config_file).await } diff --git a/src/lib.rs b/src/lib.rs index 7d53291..d610009 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,11 +114,7 @@ mod tests { file_server_root: None, }; spawn (async move { - let opt = server::Opt { - - }; - - server::main (config_file, opt).await.unwrap (); + server::main (config_file).await.unwrap (); }); tokio::time::delay_for (std::time::Duration::from_millis (500)).await; diff --git a/src/relay/mod.rs b/src/relay/mod.rs index cb84e4f..30844b3 100644 --- a/src/relay/mod.rs +++ b/src/relay/mod.rs @@ -1,5 +1,3 @@ -pub mod watcher; - use std::{ error::Error, collections::*, diff --git a/src/relay/watcher.rs b/src/relay/watcher.rs deleted file mode 100644 index 69820ed..0000000 --- a/src/relay/watcher.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Watchers on the wall was the last good episode of Game of Thrones - -use std::{ - collections::*, - sync::Arc, - time::Duration, -}; - -use futures::channel::oneshot; -use tokio::{ - sync::Mutex, - time::delay_for, -}; - -pub struct Watchers { - pub senders: HashMap >, -} - -impl Default for Watchers { - fn default () -> Self { - Self { - senders: Default::default (), - } - } -} - -impl Watchers { - pub fn add_watcher_with_id (&mut self, s: oneshot::Sender , id: String) { - self.senders.insert (id, s); - } - - pub fn remove_watcher (&mut self, id: &str) { - self.senders.remove (id); - } - - pub fn wake_one (&mut self, msg: T, id: &str) -> bool { - //println! ("wake_one {}", id); - - if let Some (waiter) = self.senders.remove (id) { - waiter.send (msg).ok (); - true - } - else { - false - } - } - - pub fn num_watchers (&self) -> usize { - self.senders.len () - } - - pub async fn long_poll (that: Arc >, id: String) -> Option { - //println! ("long_poll {}", id); - - let (s, r) = oneshot::channel (); - let timeout = Duration::from_secs (5); - - let id_2 = id.clone (); - { - let mut that = that.lock ().await; - that.add_watcher_with_id (s, id_2); - //println! ("Added server {}", id); - } - - tokio::spawn (async move { - delay_for (timeout).await; - let mut that = that.lock ().await; - that.remove_watcher (&id); - //println! ("Removed server {}", id); - }); - - if let Ok (message) = r.await { - Some (message) - } - else { - None - } - } -} diff --git a/src/server/mod.rs b/src/server/mod.rs index cf0b305..c5986ed 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -24,7 +24,6 @@ pub mod file_server; struct ServerState { config: Config, - opt: Opt, handlebars: Handlebars <'static>, client: Client, } @@ -118,12 +117,7 @@ pub struct Config { pub file_server_root: Option , } -#[derive (Clone)] -pub struct Opt { - -} - -pub async fn main (config_file: ConfigFile, opt: Opt) +pub async fn main (config_file: ConfigFile) -> Result <(), Box > { use std::convert::TryInto; @@ -149,7 +143,6 @@ pub async fn main (config_file: ConfigFile, opt: Opt) relay_url: config_file.relay_url, file_server_root: config_file.file_server_root, }, - opt, handlebars, client, });