deadlock less

This commit is contained in:
Joe Ardent 2025-09-04 11:48:38 -07:00
parent 6167522aaa
commit 00092dc97b
3 changed files with 26 additions and 19 deletions

View file

@ -84,18 +84,6 @@ impl App {
pub async fn handle_events(&mut self) -> Result<()> { pub async fn handle_events(&mut self) -> Result<()> {
tokio::select! { tokio::select! {
terminal_event = self.terminal_events.next().fuse() => {
if let Some(Ok(evt)) = terminal_event {
match evt {
Event::Key(key)
if key.kind == KeyEventKind::Press
=> self.handle_key_event(key, evt).await,
Event::Mouse(_) => {}
Event::Resize(_, _) => {}
_ => {}
}
}
}
jocal_event = self.jocal_event_rx.recv().fuse() => { jocal_event = self.jocal_event_rx.recv().fuse() => {
if let Some(event) = jocal_event { if let Some(event) = jocal_event {
log::trace!("got JocalEvent {event:?}"); log::trace!("got JocalEvent {event:?}");
@ -114,6 +102,19 @@ impl App {
} }
} }
} }
terminal_event = self.terminal_events.next().fuse() => {
if let Some(Ok(evt)) = terminal_event {
match evt {
Event::Key(key)
if key.kind == KeyEventKind::Press
=> self.handle_key_event(key, evt).await,
Event::Mouse(_) => {}
Event::Resize(_, _) => {}
_ => {}
}
}
}
} }
Ok(()) Ok(())

View file

@ -32,6 +32,8 @@ impl JocalService {
log::info!("starting http server"); log::info!("starting http server");
// need to make a custom tls acceptor, see
// https://github.com/programatik29/axum-server/blob/master/examples/rustls_session.rs
axum_server::bind_rustls(addr, ssl_config) axum_server::bind_rustls(addr, ssl_config)
.handle(handle) .handle(handle)
.serve(app.into_make_service_with_connect_info::<SocketAddr>()) .serve(app.into_make_service_with_connect_info::<SocketAddr>())

View file

@ -30,7 +30,7 @@ use transfer::Session;
pub const DEFAULT_PORT: u16 = 53317; pub const DEFAULT_PORT: u16 = 53317;
pub const MULTICAST_IP: Ipv4Addr = Ipv4Addr::new(224, 0, 0, 167); pub const MULTICAST_IP: Ipv4Addr = Ipv4Addr::new(224, 0, 0, 167);
pub const DEFAULT_INTERVAL: Duration = Duration::from_micros(33333); pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(100);
pub type Peers = Arc<Mutex<BTreeMap<String, (SocketAddr, Device)>>>; pub type Peers = Arc<Mutex<BTreeMap<String, (SocketAddr, Device)>>>;
pub type Sessions = Arc<Mutex<BTreeMap<String, Session>>>; // Session ID to Session pub type Sessions = Arc<Mutex<BTreeMap<String, Session>>>; // Session ID to Session
@ -178,22 +178,26 @@ impl JocalService {
let service = self.clone(); let service = self.clone();
handles.spawn(async move { handles.spawn(async move {
loop { loop {
if let Err(e) = service.announce(None).await {
error!("Announcement error: {e}");
}
tokio::time::sleep(Duration::from_secs(2)).await;
let rstate = service.running_state.lock().await; let rstate = service.running_state.lock().await;
if *rstate == RunningState::Stopping { if *rstate == RunningState::Stopping {
break; break;
} }
if let Err(e) = service.announce(None).await {
error!("Announcement error: {e}");
}
tokio::time::sleep(Duration::from_secs(2)).await;
} }
JocalTasks::Udp JocalTasks::Udp
}); });
} }
pub async fn stop(&self) { pub async fn stop(&self) {
{
let mut rstate = self.running_state.lock().await; let mut rstate = self.running_state.lock().await;
*rstate = RunningState::Stopping; *rstate = RunningState::Stopping;
}
log::info!("shutting down http server"); log::info!("shutting down http server");
self.http_handle self.http_handle
.get() .get()