mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-21 08:33:19 +03:00
remove inactive emulation handles
This commit is contained in:
@@ -138,7 +138,7 @@ impl ListenTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProtoEvent::Leave(_) => {
|
ProtoEvent::Leave(_) => {
|
||||||
self.emulation_proxy.release_keys(addr);
|
self.emulation_proxy.remove(addr);
|
||||||
self.listener.reply(addr, ProtoEvent::Ack(0)).await;
|
self.listener.reply(addr, ProtoEvent::Ack(0)).await;
|
||||||
}
|
}
|
||||||
ProtoEvent::Input(event) => self.emulation_proxy.consume(event, addr),
|
ProtoEvent::Input(event) => self.emulation_proxy.consume(event, addr),
|
||||||
@@ -163,9 +163,9 @@ impl ListenTask {
|
|||||||
},
|
},
|
||||||
_ = interval.tick() => {
|
_ = interval.tick() => {
|
||||||
last_response.retain(|&addr,instant| {
|
last_response.retain(|&addr,instant| {
|
||||||
if instant.elapsed() > Duration::from_secs(5) {
|
if instant.elapsed() > Duration::from_secs(1) {
|
||||||
log::warn!("releasing keys: {addr} not responding!");
|
log::warn!("releasing keys: {addr} not responding!");
|
||||||
self.emulation_proxy.release_keys(addr);
|
self.emulation_proxy.remove(addr);
|
||||||
self.event_tx.send(EmulationEvent::Disconnected { addr }).expect("channel closed");
|
self.event_tx.send(EmulationEvent::Disconnected { addr }).expect("channel closed");
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
@@ -192,7 +192,7 @@ pub(crate) struct EmulationProxy {
|
|||||||
|
|
||||||
enum ProxyRequest {
|
enum ProxyRequest {
|
||||||
Input(Event, SocketAddr),
|
Input(Event, SocketAddr),
|
||||||
ReleaseKeys(SocketAddr),
|
Remove(SocketAddr),
|
||||||
Terminate,
|
Terminate,
|
||||||
Reenable,
|
Reenable,
|
||||||
}
|
}
|
||||||
@@ -241,9 +241,9 @@ impl EmulationProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn release_keys(&self, addr: SocketAddr) {
|
fn remove(&self, addr: SocketAddr) {
|
||||||
self.request_tx
|
self.request_tx
|
||||||
.send(ProxyRequest::ReleaseKeys(addr))
|
.send(ProxyRequest::Remove(addr))
|
||||||
.expect("channel closed");
|
.expect("channel closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ impl EmulationTask {
|
|||||||
ProxyRequest::Reenable => break,
|
ProxyRequest::Reenable => break,
|
||||||
ProxyRequest::Terminate => return,
|
ProxyRequest::Terminate => return,
|
||||||
ProxyRequest::Input(..) => { /* emulation inactive => ignore */ }
|
ProxyRequest::Input(..) => { /* emulation inactive => ignore */ }
|
||||||
ProxyRequest::ReleaseKeys(..) => { /* emulation inactive => ignore */ }
|
ProxyRequest::Remove(..) => { /* emulation inactive => ignore */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,9 +352,9 @@ impl EmulationTask {
|
|||||||
};
|
};
|
||||||
emulation.consume(event, handle).await?;
|
emulation.consume(event, handle).await?;
|
||||||
},
|
},
|
||||||
ProxyRequest::ReleaseKeys(addr) => {
|
ProxyRequest::Remove(addr) => {
|
||||||
if let Some(&handle) = self.handles.get(&addr) {
|
if let Some(handle) = self.handles.remove(&addr) {
|
||||||
emulation.release_keys(handle).await?
|
emulation.destroy(handle).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProxyRequest::Terminate => break Ok(()),
|
ProxyRequest::Terminate => break Ok(()),
|
||||||
@@ -379,7 +379,7 @@ async fn wait_for_termination(rx: &mut Receiver<ProxyRequest>) {
|
|||||||
match rx.recv().await.expect("channel closed") {
|
match rx.recv().await.expect("channel closed") {
|
||||||
ProxyRequest::Terminate => return,
|
ProxyRequest::Terminate => return,
|
||||||
ProxyRequest::Input(_, _) => continue,
|
ProxyRequest::Input(_, _) => continue,
|
||||||
ProxyRequest::ReleaseKeys(_) => continue,
|
ProxyRequest::Remove(_) => continue,
|
||||||
ProxyRequest::Reenable => continue,
|
ProxyRequest::Reenable => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user