Skip to content

Commit a1e2201

Browse files
committed
handle restarting with restart_requested shared variable
1 parent 03c3b81 commit a1e2201

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ pub struct AppConfig {
142142
pub ev_battery_logger: Option<PathBuf>,
143143
pub ev_battery_capacity: u64,
144144
pub ev_factor: f32,
145+
146+
#[serde(skip)]
147+
pub restart_requested: bool,
145148
}
146149

147150
impl Default for AppConfig {
@@ -176,6 +179,7 @@ impl Default for AppConfig {
176179
ev_battery_logger: None,
177180
ev_battery_capacity: 22000,
178181
ev_factor: 0.075,
182+
restart_requested: false,
179183
}
180184
}
181185
}

src/io_uring.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ async fn transfer_monitor(
8787
usb_bytes_written: Arc<AtomicUsize>,
8888
tcp_bytes_written: Arc<AtomicUsize>,
8989
read_timeout: Duration,
90+
config: SharedConfig,
9091
) -> Result<()> {
9192
let mut usb_bytes_out_last: usize = 0;
9293
let mut tcp_bytes_out_last: usize = 0;
@@ -153,6 +154,12 @@ async fn transfer_monitor(
153154
stall_tcp_bytes_last = tcp_bytes_out;
154155
}
155156

157+
// check if we need to restart
158+
if config.read().await.restart_requested {
159+
config.write().await.restart_requested = false;
160+
return Err("config reload request => restarting connection".into());
161+
}
162+
156163
sleep(Duration::from_millis(100)).await;
157164
}
158165
}
@@ -384,6 +391,7 @@ pub async fn io_loop(
384391
file_bytes,
385392
stream_bytes,
386393
read_timeout,
394+
config.clone(),
387395
));
388396

389397
// Stop as soon as one of them errors

0 commit comments

Comments
 (0)