hotfix accept bug

https://github.com/webrtc-rs/webrtc/issues/614
This commit is contained in:
Ferdinand Schober
2024-09-20 22:55:21 +02:00
parent 3e62739f7e
commit b41ee94a2b
2 changed files with 21 additions and 8 deletions

View File

@@ -151,7 +151,15 @@ impl LanMouseConnection {
}
tokio::time::sleep(Duration::from_millis(500)).await;
let mut buf = [0u8; MAX_EVENT_SIZE];
conn.recv(&mut buf).await;
if let Err(e) = conn.recv(&mut buf).await {
log::warn!("recv(): client ({handle}) @ {addr} connection closed: {e}");
conns.lock().await.remove(&addr);
server.set_active_addr(handle, None);
let active: Vec<SocketAddr> =
conns.lock().await.keys().copied().collect();
log::info!("active connections: {active:?}");
break;
}
}
});
}

View File

@@ -1,7 +1,7 @@
use futures::{Stream, StreamExt};
use lan_mouse_proto::{ProtoEvent, MAX_EVENT_SIZE};
use local_channel::mpsc::{channel, Receiver, Sender};
use std::{net::SocketAddr, rc::Rc, sync::Arc};
use std::{net::SocketAddr, rc::Rc, sync::Arc, time::Duration};
use thiserror::Error;
use tokio::{
sync::Mutex,
@@ -50,12 +50,17 @@ impl LanMouseListener {
let tx = listen_tx.clone();
let listen_task: JoinHandle<()> = spawn_local(async move {
loop {
let (conn, addr) = match listener.accept().await {
Ok(c) => c,
Err(e) => {
log::warn!("accept: {e}");
continue;
}
log::info!("accepting ...");
let sleep = tokio::time::sleep(Duration::from_secs(2));
let (conn, addr) = tokio::select! {
_ = sleep => continue,
c = listener.accept() => match c {
Ok(c) => c,
Err(e) => {
log::warn!("accept: {e}");
continue;
}
},
};
log::info!("dtls client connected, ip: {addr}");
let mut conns = conns_clone.lock().await;