From ca1ade1341d6b0294421207fdd3531a152c13b68 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Tue, 19 Nov 2019 23:44:42 -0500 Subject: [PATCH 1/2] Revert "Removed old Tokio version from Cargo.toml" This reverts commit 7e85a8750b8f5e18720890c6c82f8540ab390f0b. --- Cargo.lock | 3 +++ Cargo.toml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 60d6a9e..0a3d442 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1782,7 +1782,10 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "odds 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "warp 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "weak-table 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 9813c70..4e2d63d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,10 @@ hyper = "^0.12.35" hyper13 = { package = "hyper", version="0.13.0-alpha.4", features = ["unstable-stream"] } log = "^0.4.8" matches = "^0.1.8" -odds = { version = "^0.3.1", features = ["std-vec"] } +odds = { version = "0.3.1", features = ["std-vec"] } +tokio = "0.1.22" tokio2 = { package = "tokio", version="0.2.0-alpha.6" } +tokio-codec = "0.1.1" +tokio-io = "0.1.12" warp = "0.1.20" weak-table = "^0.2.3" From 3f7adb3bd627e88f49eeffeecd28edc2c8979aee Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sun, 17 Nov 2019 23:55:55 -0500 Subject: [PATCH 2/2] Bind to multiple addresses if given a DNS name --- src/commands/relay.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/commands/relay.rs b/src/commands/relay.rs index 96f6514..2d48766 100644 --- a/src/commands/relay.rs +++ b/src/commands/relay.rs @@ -101,9 +101,13 @@ pub fn options() -> App<'static, 'static> { pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> { let channel_map = Arc::new(Mutex::new(WeakValueHashMap::>>::new())); - let addr_str = args.value_of("listen").ok_or("Listen address wasn't provided")?; - let addr = addr_str.to_socket_addrs()?.next().ok_or("Listen address didn't resolve")?; + + let addrs = addr_str.to_socket_addrs()?; + info!("Binding to {:?}", addrs); + if addrs.len() == 0 { + return Err("Listen address didn't resolve".into()); + } let channel = path!("live" / String).map(move |name: String| { let channel = channel_map.lock().unwrap() @@ -134,5 +138,11 @@ pub fn run(args: &ArgMatches) -> Result<(), WebmetroError> { .or(get) .or(post_put); - Ok(warp::serve(routes).run(addr)) + let mut rt = tokio::runtime::Runtime::new()?; + + for do_serve in addrs.map(|addr| warp::serve(routes.clone()).try_bind(addr)) { + rt.spawn(do_serve); + } + + rt.shutdown_on_idle().wait().map_err(|_| "Shutdown error.".into()) }