Merge branch 'multibind'

This commit is contained in:
Tangent Wantwight 2019-11-20 00:24:01 -05:00
commit 0c48d59e3a
3 changed files with 20 additions and 4 deletions

3
Cargo.lock generated
View File

@ -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)",
]

View File

@ -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"

View File

@ -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::<String, Weak<Mutex<Channel>>>::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())
}