mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-16 01:51:27 +03:00
ignore requests with capture / emulation disabled
otherwise the server would hang when trying to enable clients
This commit is contained in:
@@ -187,7 +187,10 @@ impl Server {
|
|||||||
self.notify_frontend(FrontendEvent::PortChanged(self.port.get(), None));
|
self.notify_frontend(FrontendEvent::PortChanged(self.port.get(), None));
|
||||||
}
|
}
|
||||||
request = request_rx.recv() => {
|
request = request_rx.recv() => {
|
||||||
self.handle_request(&capture_tx.clone(), &emulation_tx.clone(), request.expect("channel closed")).await;
|
let request = request.expect("channel closed");
|
||||||
|
log::debug!("received frontend request: {request:?}");
|
||||||
|
self.handle_request(&capture_tx.clone(), &emulation_tx.clone(), request).await;
|
||||||
|
log::debug!("handled frontend request");
|
||||||
}
|
}
|
||||||
_ = self.notifies.frontend_event_pending.notified() => {
|
_ = self.notifies.frontend_event_pending.notified() => {
|
||||||
let events = self
|
let events = self
|
||||||
@@ -376,6 +379,7 @@ impl Server {
|
|||||||
emulate: &Sender<EmulationEvent>,
|
emulate: &Sender<EmulationEvent>,
|
||||||
handle: ClientHandle,
|
handle: ClientHandle,
|
||||||
) {
|
) {
|
||||||
|
log::debug!("deactivating client {handle}");
|
||||||
match self.client_manager.borrow_mut().get_mut(handle) {
|
match self.client_manager.borrow_mut().get_mut(handle) {
|
||||||
Some((_, s)) => s.active = false,
|
Some((_, s)) => s.active = false,
|
||||||
None => return,
|
None => return,
|
||||||
@@ -383,6 +387,7 @@ impl Server {
|
|||||||
|
|
||||||
let _ = capture.send(CaptureEvent::Destroy(handle)).await;
|
let _ = capture.send(CaptureEvent::Destroy(handle)).await;
|
||||||
let _ = emulate.send(EmulationEvent::Destroy(handle)).await;
|
let _ = emulate.send(EmulationEvent::Destroy(handle)).await;
|
||||||
|
log::debug!("deactivating client {handle} done");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn activate_client(
|
pub async fn activate_client(
|
||||||
@@ -391,6 +396,7 @@ impl Server {
|
|||||||
emulate: &Sender<EmulationEvent>,
|
emulate: &Sender<EmulationEvent>,
|
||||||
handle: ClientHandle,
|
handle: ClientHandle,
|
||||||
) {
|
) {
|
||||||
|
log::debug!("activating client");
|
||||||
/* deactivate potential other client at this position */
|
/* deactivate potential other client at this position */
|
||||||
let pos = match self.client_manager.borrow().get(handle) {
|
let pos = match self.client_manager.borrow().get(handle) {
|
||||||
Some((client, _)) => client.pos,
|
Some((client, _)) => client.pos,
|
||||||
@@ -412,8 +418,11 @@ impl Server {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* notify emulation, capture and frontends */
|
/* notify emulation, capture and frontends */
|
||||||
|
log::debug!("capture.send(Create)");
|
||||||
let _ = capture.send(CaptureEvent::Create(handle, pos.into())).await;
|
let _ = capture.send(CaptureEvent::Create(handle, pos.into())).await;
|
||||||
|
log::debug!("emulation.send(Create)");
|
||||||
let _ = emulate.send(EmulationEvent::Create(handle)).await;
|
let _ = emulate.send(EmulationEvent::Create(handle)).await;
|
||||||
|
log::debug!("activating client {handle} done");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_client(
|
pub async fn remove_client(
|
||||||
|
|||||||
@@ -61,9 +61,12 @@ async fn capture_task(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allow cancellation
|
// allow cancellation
|
||||||
tokio::select! {
|
loop {
|
||||||
_ = server.capture_notified() => {},
|
tokio::select! {
|
||||||
_ = server.cancelled() => break,
|
_ = notify_rx.recv() => continue, /* need to ignore requests here! */
|
||||||
|
_ = server.capture_notified() => break,
|
||||||
|
_ = server.cancelled() => return,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,26 +57,22 @@ async fn emulation_task(
|
|||||||
capture_tx: Sender<CaptureEvent>,
|
capture_tx: Sender<CaptureEvent>,
|
||||||
) {
|
) {
|
||||||
loop {
|
loop {
|
||||||
match do_emulation(&server, &mut rx, &mut udp_rx, &sender_tx, &capture_tx).await {
|
if let Err(e) = do_emulation(&server, &mut rx, &mut udp_rx, &sender_tx, &capture_tx).await {
|
||||||
Ok(()) => {}
|
log::warn!("input emulation exited: {e}");
|
||||||
Err(e) => {
|
|
||||||
log::warn!("input emulation exited: {e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
server.set_emulation_status(Status::Disabled);
|
server.set_emulation_status(Status::Disabled);
|
||||||
|
if server.is_cancelled() {
|
||||||
if server.notifies.cancel.is_cancelled() {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log::info!("waiting for user to request input emulation ...");
|
|
||||||
|
|
||||||
// allow cancellation
|
// allow cancellation
|
||||||
tokio::select! {
|
loop {
|
||||||
_ = server.emulation_notified() => {},
|
tokio::select! {
|
||||||
_ = server.cancelled() => break,
|
_ = rx.recv() => continue, /* need to ignore requests here! */
|
||||||
|
_ = server.emulation_notified() => break,
|
||||||
|
_ = server.cancelled() => return,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("... done");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user