use std::{ error::Error, fs::File, sync::Arc, }; use tokio::sync::oneshot; mod load_toml; use ptth::relay; use ptth::relay::RelayState; #[tokio::main] async fn main () -> Result <(), Box > { let config_file = load_toml::load ("config/ptth_relay.toml"); eprintln! ("ptth_relay Git version: {:?}", ptth::git_version::GIT_VERSION); let rx = { let (tx, rx) = oneshot::channel::<()> (); // I have to put the tx into a Cell here so that if Ctrl-C gets // called multiple times, we won't send multiple shutdowns to the // oneshot channel. (Which would be a compile error) let tx = Some (tx); let tx = std::cell::Cell::new (tx); ctrlc::set_handler (move ||{ let tx = tx.replace (None); if let Some (tx) = tx { tx.send (()).unwrap (); } }).expect ("Error setting Ctrl-C handler"); rx }; relay::run_relay ( Arc::new (RelayState::from (&config_file)), rx ).await }