File tree Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 11use futures:: { Stream , StreamExt } ;
22use lan_mouse_proto:: { ProtoEvent , MAX_EVENT_SIZE } ;
33use 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 } ;
55use thiserror:: Error ;
66use 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 ;
You can’t perform that action at this time.
0 commit comments