mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-13 17:51:29 +03:00
@@ -151,7 +151,15 @@ impl LanMouseConnection {
|
|||||||
}
|
}
|
||||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||||
let mut buf = [0u8; MAX_EVENT_SIZE];
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use lan_mouse_proto::{ProtoEvent, MAX_EVENT_SIZE};
|
use lan_mouse_proto::{ProtoEvent, MAX_EVENT_SIZE};
|
||||||
use local_channel::mpsc::{channel, Receiver, Sender};
|
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 thiserror::Error;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
@@ -50,12 +50,17 @@ impl LanMouseListener {
|
|||||||
let tx = listen_tx.clone();
|
let tx = listen_tx.clone();
|
||||||
let listen_task: JoinHandle<()> = spawn_local(async move {
|
let listen_task: JoinHandle<()> = spawn_local(async move {
|
||||||
loop {
|
loop {
|
||||||
let (conn, addr) = match listener.accept().await {
|
log::info!("accepting ...");
|
||||||
Ok(c) => c,
|
let sleep = tokio::time::sleep(Duration::from_secs(2));
|
||||||
Err(e) => {
|
let (conn, addr) = tokio::select! {
|
||||||
log::warn!("accept: {e}");
|
_ = sleep => continue,
|
||||||
continue;
|
c = listener.accept() => match c {
|
||||||
}
|
Ok(c) => c,
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("accept: {e}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
log::info!("dtls client connected, ip: {addr}");
|
log::info!("dtls client connected, ip: {addr}");
|
||||||
let mut conns = conns_clone.lock().await;
|
let mut conns = conns_clone.lock().await;
|
||||||
|
|||||||
Reference in New Issue
Block a user