From 06963a8a2861926c2e7d6560a5812d660805dd9f Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Fri, 3 Feb 2023 11:44:18 +0100 Subject: [PATCH] apply some CR --- Cargo.lock | 29 ----------------------------- Cargo.toml | 1 - src/main.rs | 6 ++---- src/provider.rs | 9 ++++++--- 4 files changed, 8 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bce8f20..bcd232d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -383,16 +383,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "ctrlc" -version = "3.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71" -dependencies = [ - "nix", - "windows-sys", -] - [[package]] name = "cuckoofilter" version = "0.5.0" @@ -955,18 +945,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "nix" -version = "0.26.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" -dependencies = [ - "bitflags", - "cfg-if", - "libc", - "static_assertions", -] - [[package]] name = "nom" version = "7.1.3" @@ -1768,7 +1746,6 @@ dependencies = [ "bytes", "clap", "console", - "ctrlc", "der", "ed25519-dalek", "futures", @@ -1964,12 +1941,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 90b98b3..966f72e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ blake3 = "1.3.3" bytes = "1" clap = { version = "4", features = ["derive"], optional = true } console = { version = "0.15.5", optional = true } -ctrlc = "3.2.4" der = { version = "0.6", features = ["alloc", "derive"] } ed25519-dalek = { version = "1.0.1", features = ["serde"] } futures = "0.3.25" diff --git a/src/main.rs b/src/main.rs index e043881..50203cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use indicatif::{ use sendme::protocol::AuthToken; use sendme::provider::Ticket; use tokio::io::AsyncWriteExt; -use tokio::sync::{mpsc, Mutex}; +use tokio::sync::Mutex; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use sendme::{get, provider, util, Keypair, PeerId}; @@ -205,9 +205,7 @@ async fn main() -> Result<()> { .println(format!("All-in-one ticket: {}", provider.ticket(hash))) .await; - let (s, mut r) = mpsc::channel(1); - ctrlc::set_handler(move || s.try_send(()).expect("failed to send shutdown signal"))?; - r.recv().await; + tokio::signal::ctrl_c().await?; out_writer.println("Shutting down...").await; provider.shutdown().await?; diff --git a/src/provider.rs b/src/provider.rs index 3034c28..40ed762 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -136,6 +136,12 @@ impl Builder { loop { tokio::select! { + biased; + + _ = &mut shutdown => { + break; + } + Some(mut connection) = server.accept() => { let db = db.clone(); let events = events.clone(); @@ -156,9 +162,6 @@ impl Builder { } }); } - _ = &mut shutdown => { - break; - } } } }