Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish = true
maintenance = { status = "experimental" }

[dependencies]
tokio = { version = "1.34", features = ["rt", "net", "macros", "io-util", "sync", "time"] }
tokio = { version = "1.34", features = ["rt", "net", "macros", "io-util", "sync", "time", "signal"] }
structopt = "0.3"
log = "0.4"
env_logger = "0.10"
Expand Down
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use futures::future::join_all;
use serde::Deserialize;
use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader, BufWriter};
use tokio::net::{TcpListener, TcpStream};
#[cfg(unix)]
use tokio::signal::unix::{signal, SignalKind};
use tokio::sync::{mpsc, oneshot};

// Use Jemalloc only for musl-64 bits platforms
Expand Down Expand Up @@ -240,7 +242,17 @@ impl Server {
for mut bridge in self.devices {
tasks.push(tokio::spawn(async move { bridge.run().await }));
}
join_all(tasks).await;

#[cfg(unix)]
let mut sigterm = signal(SignalKind::terminate()).unwrap();
tokio::select! {
_ = join_all(tasks) => debug!("All tasks finished"),
_ = tokio::signal::ctrl_c() => debug!("Received Ctrl+C"),
//#[cfg(unix)]
_ = sigterm.recv() => debug!("Received SIGTERM"),
}

info!("Shutting down");
}

pub async fn launch(config_file: &str) -> std::result::Result<(), config::ConfigError> {
Expand Down