From 5222eff37b48f08ed0b3c47dd6f06ff45d89d21f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 Feb 2025 12:24:26 +0000 Subject: [PATCH] Make config::startup()'s G callback async We're going to call tokio::net::TcpListener::bind(), which is async. Signed-off-by: Ian Jackson --- client/client.rs | 6 +++--- server/server.rs | 4 ++-- src/config.rs | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/client.rs b/client/client.rs index 75c4562..c002a43 100644 --- a/client/client.rs +++ b/client/client.rs @@ -344,14 +344,14 @@ async fn main() { let opts = ::parse(); let (ics,) = config::startup( "hippotat", LinkEnd::Client, - &opts.config, &opts.log, |_, ics| + &opts.config, &opts.log, |_, ics| { PrintConfigOpt(&opts.print_config) .implement(ics, )?; Ok(()) - }, |_, ics| { + }, |_, ics| async move { Ok((ics,)) - }); + }).await; let hclient = reqwest::Client::builder() .http1_title_case_headers() diff --git a/server/server.rs b/server/server.rs index a5c71a3..1aa6f26 100644 --- a/server/server.rs +++ b/server/server.rs @@ -190,7 +190,7 @@ async fn async_main(opts: Opts, daemon: Option) { Ok(Some(global_config)) - }, |global_config, ics| { + }, |global_config, ics| async { let global_config = global_config.expect("some instances"); @@ -312,7 +312,7 @@ async fn async_main(opts: Opts, daemon: Option) { tasks.push((ipif, format!("ipif"))); Ok(()) - }); + }).await; if let Some(daemon) = daemon { daemon.complete(); diff --git a/src/config.rs b/src/config.rs index 0a38080..df80d1e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1065,13 +1065,14 @@ pub fn read(opts: &CommonOpts, end: LinkEnd) (server_name, ics) } -pub fn startup(progname: &str, end: LinkEnd, +pub async fn startup(progname: &str, end: LinkEnd, opts: &CommonOpts, logopts: &LogOpts, f: F, g: G) -> U where F: FnOnce(Option, &[InstanceConfig]) -> Result, - G: FnOnce(T, Vec) -> Result, + G: FnOnce(T, Vec) -> GFut, + GFut: Future>, { - (||{ + async { dedup_eyre_setup()?; let (server_name, ics) = config::read(opts, end)?; @@ -1079,10 +1080,10 @@ where F: FnOnce(Option, &[InstanceConfig]) -> Result, if ics.is_empty() { throw!(anyhow!("no associations, quitting")); } logopts.log_init()?; - let u = g(t, ics)?; + let u = g(t, ics).await?; Ok::<_,AE>(u) - })().unwrap_or_else(|e| { + }.await.unwrap_or_else(|e| { eprintln!("{}: startup error: {}", progname, &e); process::exit(8); }) -- 2.30.2