Skip to content

Commit f252c3d

Browse files
robinohsGrSto
authored andcommitted
refactor: replace tokio oneshot channel with crossbeam channel
- remove tokio dependency
1 parent 6c56075 commit f252c3d

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ spin_sleep = "1.3.1"
6161
tempfile = "3.20.0"
6262
thiserror = "2.0.12"
6363
thread-priority = "1.2.0"
64-
tokio = { version = "1.45.1", features = ["sync"] }
6564
uom = { version = "0.37.0", features = ["si", "serde", "u64"] }
6665

6766
[build-dependencies]

src/commands/start.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::{
66
time::Duration,
77
};
88

9+
use crossbeam::channel::unbounded;
910
use log::warn;
10-
use tokio::sync::oneshot;
1111

1212
use crate::{cli::opt::StartArgs, commands::utils, phork::namespace::NS_NAME_LINK, runtime::Runtime};
1313

@@ -23,19 +23,16 @@ pub(crate) fn run(start_args: StartArgs) -> eyre::Result<()> {
2323
let reconfiguration_delay = Duration::from_micros(micros_reconfiguration_delay);
2424

2525
// set up Ctrl-C handler for cleanup before exit
26-
let (tx, rx) = oneshot::channel::<()>();
27-
let mut tx = Option::Some(tx);
26+
let (tx, rx) = unbounded::<()>();
2827
let exiting = Arc::new(AtomicBool::new(false));
2928
ctrlc::set_handler(move || {
3029
if exiting.load(Ordering::Relaxed) {
3130
warn!("Ctrl-C received twice, exiting ungracefully. This may leave the network environment in an inconsistent state.");
3231
std::process::exit(1);
3332
} else {
34-
if let Some(tx) = tx.take() {
35-
tx.send(()).unwrap_or_else(|_| {
36-
eprintln!("Failed to send shutdown signal.");
37-
});
38-
}
33+
tx.send(()).unwrap_or_else(|_| {
34+
eprintln!("Failed to send shutdown signal.");
35+
});
3936
exiting.store(true, Ordering::Relaxed);
4037
}
4138
})

src/runtime.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use crossbeam::channel::Receiver;
12
use eyre::{bail, OptionExt, Result};
2-
use log::{debug, info};
3+
use log::{debug, error, info};
34
use pnet::datalink::{self, Channel, ChannelType, Config, NetworkInterface};
45
use std::{
56
collections::HashMap,
@@ -10,7 +11,6 @@ use std::{
1011
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
1112
};
1213
use tempfile::NamedTempFile;
13-
use tokio::sync::oneshot::Receiver;
1414
use uom::si::information::byte;
1515

1616
use crate::{
@@ -150,11 +150,11 @@ impl Runtime {
150150

151151
// Handle shutdown signal
152152
// This thread will block until a shutdown signal is received.
153-
thread::spawn(move || {
154-
stop_rx.blocking_recv().unwrap_or_else(|_| {
155-
eprintln!("Failed to receive shutdown signal.");
156-
});
157-
info!("Received shutdown signal, stopping phantomlink...");
153+
thread::spawn(move || match stop_rx.recv() {
154+
Ok(_) => info!("Received shutdown signal, stopping phantomlink..."),
155+
Err(e) => {
156+
error!("Error receiving shutdown signal: {}", e);
157+
}
158158
})
159159
.join()
160160
.unwrap();

0 commit comments

Comments
 (0)