Skip to content

Commit 80972ec

Browse files
committed
recompute stats_interval and read_timeout on config reload
1 parent 88c065f commit 80972ec

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

src/io_uring.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ async fn transfer_monitor(
9696
let mut report_time = Instant::now();
9797
let mut stall_check = Instant::now();
9898

99+
info!(
100+
"{} ⚙️ Showing transfer statistics: <b><blue>{}</>",
101+
NAME,
102+
match stats_interval {
103+
Some(d) => format_duration(d).to_string(),
104+
None => "disabled".to_string(),
105+
}
106+
);
107+
99108
loop {
100109
// load current total transfer from AtomicUsize:
101110
let usb_bytes_out = usb_bytes_written.load(Ordering::Relaxed);
@@ -198,10 +207,8 @@ async fn tcp_wait_for_connection(listener: &mut TcpListener) -> Result<TcpStream
198207
}
199208

200209
pub async fn io_loop(
201-
stats_interval: Option<Duration>,
202210
need_restart: Arc<Notify>,
203211
tcp_start: Arc<Notify>,
204-
read_timeout: Duration,
205212
config: SharedConfig,
206213
) -> Result<()> {
207214
// prepare/bind needed TCP listeners
@@ -213,6 +220,16 @@ pub async fn io_loop(
213220
// reload new config
214221
let config = config.read().await.clone();
215222

223+
// generate Durations from configured seconds
224+
let stats_interval = {
225+
if config.stats_interval == 0 {
226+
None
227+
} else {
228+
Some(Duration::from_secs(config.stats_interval.into()))
229+
}
230+
};
231+
let read_timeout = Duration::from_secs(config.timeout_secs.into());
232+
216233
if !config.wired.is_some() && md_listener.is_none() {
217234
info!("{} 🛰️ Starting TCP server for MD...", NAME);
218235
let bind_addr = format!("0.0.0.0:{}", TCP_SERVER_PORT).parse().unwrap();

src/main.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,6 @@ fn main() {
304304
}
305305
debug!("{} ⚙️ startup configuration: {:#?}", NAME, config);
306306

307-
let stats_interval = {
308-
if config.stats_interval == 0 {
309-
None
310-
} else {
311-
Some(Duration::from_secs(config.stats_interval.into()))
312-
}
313-
};
314-
let read_timeout = Duration::from_secs(config.timeout_secs.into());
315-
316307
if let Some(ref wired) = config.wired {
317308
info!(
318309
"{} 🔌 enabled wired USB connection with {:04X?}",
@@ -324,14 +315,6 @@ fn main() {
324315
NAME,
325316
config.logfile.display()
326317
);
327-
info!(
328-
"{} ⚙️ Showing transfer statistics: <b><blue>{}</>",
329-
NAME,
330-
match stats_interval {
331-
Some(d) => format_duration(d).to_string(),
332-
None => "disabled".to_string(),
333-
}
334-
);
335318

336319
// notify for syncing threads
337320
let need_restart = Arc::new(Notify::new());
@@ -348,13 +331,7 @@ fn main() {
348331
});
349332

350333
// start tokio_uring runtime simultaneously
351-
let _ = tokio_uring::start(io_loop(
352-
stats_interval,
353-
need_restart_cloned,
354-
tcp_start_cloned,
355-
read_timeout,
356-
config,
357-
));
334+
let _ = tokio_uring::start(io_loop(need_restart_cloned, tcp_start_cloned, config));
358335

359336
info!(
360337
"🚩 aa-proxy-rs terminated, running time: {}",

0 commit comments

Comments
 (0)