Skip to content

Commit 1295ef3

Browse files
committed
hotfix accept bug
webrtc-rs/webrtc#614
1 parent e3efd0b commit 1295ef3

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/connect.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,15 @@ impl LanMouseConnection {
151151
}
152152
tokio::time::sleep(Duration::from_millis(500)).await;
153153
let mut buf = [0u8; MAX_EVENT_SIZE];
154-
conn.recv(&mut buf).await;
154+
if let Err(e) = conn.recv(&mut buf).await {
155+
log::warn!("recv(): client ({handle}) @ {addr} connection closed: {e}");
156+
conns.lock().await.remove(&addr);
157+
server.set_active_addr(handle, None);
158+
let active: Vec<SocketAddr> =
159+
conns.lock().await.keys().copied().collect();
160+
log::info!("active connections: {active:?}");
161+
break;
162+
}
155163
}
156164
});
157165
}

src/listen.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use futures::{Stream, StreamExt};
22
use lan_mouse_proto::{ProtoEvent, MAX_EVENT_SIZE};
33
use local_channel::mpsc::{channel, Receiver, Sender};
4-
use std::{net::SocketAddr, rc::Rc, sync::Arc};
4+
use std::{net::SocketAddr, rc::Rc, sync::Arc, time::Duration};
55
use thiserror::Error;
66
use tokio::{
77
sync::Mutex,
@@ -50,12 +50,17 @@ impl LanMouseListener {
5050
let tx = listen_tx.clone();
5151
let listen_task: JoinHandle<()> = spawn_local(async move {
5252
loop {
53-
let (conn, addr) = match listener.accept().await {
54-
Ok(c) => c,
55-
Err(e) => {
56-
log::warn!("accept: {e}");
57-
continue;
58-
}
53+
log::info!("accepting ...");
54+
let sleep = tokio::time::sleep(Duration::from_secs(2));
55+
let (conn, addr) = tokio::select! {
56+
_ = sleep => continue,
57+
c = listener.accept() => match c {
58+
Ok(c) => c,
59+
Err(e) => {
60+
log::warn!("accept: {e}");
61+
continue;
62+
}
63+
},
5964
};
6065
log::info!("dtls client connected, ip: {addr}");
6166
let mut conns = conns_clone.lock().await;

0 commit comments

Comments
 (0)