feat: got timeline for beacons working
This commit is contained in:
@@ -15,7 +15,7 @@ use smoltcp::{
|
||||
use tokio::{
|
||||
io::{AsyncRead, AsyncWrite},
|
||||
sync::broadcast,
|
||||
task::{spawn_blocking, JoinHandle},
|
||||
task::spawn_blocking,
|
||||
};
|
||||
|
||||
use sparse_actions::{
|
||||
@@ -28,13 +28,11 @@ pub struct NetInterfaceHandle {
|
||||
tcp_handle: SocketHandle,
|
||||
|
||||
close_background: broadcast::Sender<()>,
|
||||
background_process: JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Drop for NetInterfaceHandle {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.close_background.send(());
|
||||
self.background_process.abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,27 +293,41 @@ where
|
||||
|
||||
let net = Arc::new(Mutex::new((sockets, device, iface)));
|
||||
|
||||
let background_process = spawn_blocking({
|
||||
spawn_blocking({
|
||||
let net = Arc::clone(&net);
|
||||
let tcp_handle = tcp_handle.clone();
|
||||
|
||||
move || loop {
|
||||
if close_background_recv.try_recv().is_ok() {
|
||||
break;
|
||||
}
|
||||
move || {
|
||||
let mut close_attempts = -1;
|
||||
|
||||
let delay = {
|
||||
let Ok(mut guard) = net.lock() else {
|
||||
continue;
|
||||
loop {
|
||||
if close_attempts == -1 && close_background_recv.try_recv().is_ok() {
|
||||
close_attempts = 50;
|
||||
}
|
||||
|
||||
if close_attempts == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
let delay = {
|
||||
let Ok(mut guard) = net.lock() else {
|
||||
continue;
|
||||
};
|
||||
let (ref mut s_guard, ref mut d_guard, ref mut i_guard) = *guard;
|
||||
|
||||
if close_attempts > 0 {
|
||||
let socket = s_guard.get_mut::<Socket>(tcp_handle);
|
||||
socket.close();
|
||||
}
|
||||
|
||||
let timestamp = Instant::now();
|
||||
i_guard.poll(timestamp, d_guard, s_guard);
|
||||
|
||||
i_guard.poll_delay(timestamp, s_guard)
|
||||
};
|
||||
let (ref mut s_guard, ref mut d_guard, ref mut i_guard) = *guard;
|
||||
|
||||
let timestamp = Instant::now();
|
||||
i_guard.poll(timestamp, d_guard, s_guard);
|
||||
|
||||
i_guard.poll_delay(timestamp, s_guard)
|
||||
};
|
||||
|
||||
let _ = ready_wait.wait(delay.map(Into::into));
|
||||
let _ = ready_wait.wait(delay.map(Into::into));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -324,6 +336,5 @@ where
|
||||
tcp_handle,
|
||||
|
||||
close_background,
|
||||
background_process,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user