mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-17 15:41:29 +03:00
cleanup
This commit is contained in:
@@ -97,14 +97,14 @@ impl Server {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let timer_notify = Arc::new(Notify::new()); /* notify ping timer restart */
|
let notify_ping = Arc::new(Notify::new()); /* notify ping timer restart */
|
||||||
let (frontend_tx, frontend_rx) = channel(1); /* events coming from frontends */
|
let (frontend_tx, frontend_rx) = channel(1); /* events coming from frontends */
|
||||||
let cancellation_token = CancellationToken::new(); /* notify termination */
|
let cancellation_token = CancellationToken::new(); /* notify termination */
|
||||||
let notify_capture = Arc::new(Notify::new()); /* notify capture restart */
|
let notify_capture = Arc::new(Notify::new()); /* notify capture restart */
|
||||||
let notify_emulation = Arc::new(Notify::new()); /* notify emultation restart */
|
let notify_emulation = Arc::new(Notify::new()); /* notify emultation restart */
|
||||||
|
|
||||||
// udp task
|
// udp task
|
||||||
let (mut udp_task, udp_send, udp_recv, port_tx) = network_task::new(
|
let (mut network, udp_send, udp_recv, port_tx) = network_task::new(
|
||||||
self.clone(),
|
self.clone(),
|
||||||
frontend_tx.clone(),
|
frontend_tx.clone(),
|
||||||
cancellation_token.clone(),
|
cancellation_token.clone(),
|
||||||
@@ -112,33 +112,33 @@ impl Server {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// input capture
|
// input capture
|
||||||
let (mut capture_task, capture_channel) = capture_task::new(
|
let (mut capture, capture_channel) = capture_task::new(
|
||||||
capture_backend,
|
capture_backend,
|
||||||
self.clone(),
|
self.clone(),
|
||||||
udp_send.clone(),
|
udp_send.clone(),
|
||||||
frontend_tx.clone(),
|
frontend_tx.clone(),
|
||||||
timer_notify.clone(),
|
notify_ping.clone(),
|
||||||
self.release_bind.clone(),
|
self.release_bind.clone(),
|
||||||
cancellation_token.clone(),
|
cancellation_token.clone(),
|
||||||
notify_capture.clone(),
|
notify_capture.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// input emulation
|
// input emulation
|
||||||
let (mut emulation_task, emulate_channel) = emulation_task::new(
|
let (mut emulation, emulate_channel) = emulation_task::new(
|
||||||
emulation_backend,
|
emulation_backend,
|
||||||
self.clone(),
|
self.clone(),
|
||||||
udp_recv,
|
udp_recv,
|
||||||
udp_send.clone(),
|
udp_send.clone(),
|
||||||
capture_channel.clone(),
|
capture_channel.clone(),
|
||||||
frontend_tx.clone(),
|
frontend_tx.clone(),
|
||||||
timer_notify.clone(),
|
notify_ping.clone(),
|
||||||
cancellation_token.clone(),
|
cancellation_token.clone(),
|
||||||
notify_emulation.clone(),
|
notify_emulation.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// create dns resolver
|
// create dns resolver
|
||||||
let resolver = dns::DnsResolver::new().await?;
|
let resolver = dns::DnsResolver::new().await?;
|
||||||
let (mut resolver_task, dns_req) = resolver_task::new(
|
let (mut resolver, dns_req) = resolver_task::new(
|
||||||
resolver,
|
resolver,
|
||||||
self.clone(),
|
self.clone(),
|
||||||
frontend_tx,
|
frontend_tx,
|
||||||
@@ -146,7 +146,7 @@ impl Server {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// frontend listener
|
// frontend listener
|
||||||
let (mut frontend_task, frontend_tx) = frontend_task::new(
|
let (mut frontend, frontend_tx) = frontend_task::new(
|
||||||
frontend,
|
frontend,
|
||||||
frontend_rx,
|
frontend_rx,
|
||||||
self.clone(),
|
self.clone(),
|
||||||
@@ -160,12 +160,12 @@ impl Server {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// task that pings clients to see if they are responding
|
// task that pings clients to see if they are responding
|
||||||
let mut ping_task = ping_task::new(
|
let mut ping = ping_task::new(
|
||||||
self.clone(),
|
self.clone(),
|
||||||
udp_send.clone(),
|
udp_send.clone(),
|
||||||
emulate_channel.clone(),
|
emulate_channel.clone(),
|
||||||
capture_channel.clone(),
|
capture_channel.clone(),
|
||||||
timer_notify,
|
notify_ping,
|
||||||
cancellation_token.clone(),
|
cancellation_token.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -195,26 +195,16 @@ impl Server {
|
|||||||
_ = signal::ctrl_c() => {
|
_ = signal::ctrl_c() => {
|
||||||
log::info!("terminating service");
|
log::info!("terminating service");
|
||||||
}
|
}
|
||||||
_ = &mut capture_task => { }
|
_ = &mut capture => { }
|
||||||
_ = &mut emulation_task => { }
|
_ = &mut emulation => { }
|
||||||
_ = &mut frontend_task => { }
|
_ = &mut frontend => { }
|
||||||
_ = &mut resolver_task => { }
|
_ = &mut resolver => { }
|
||||||
_ = &mut udp_task => { }
|
_ = &mut network => { }
|
||||||
_ = &mut ping_task => { }
|
_ = &mut ping => { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// cancel tasks
|
|
||||||
cancellation_token.cancel();
|
cancellation_token.cancel();
|
||||||
|
let _ = join!(capture, emulation, frontend, network, resolver, ping);
|
||||||
let _ = join!(
|
|
||||||
capture_task,
|
|
||||||
emulation_task,
|
|
||||||
frontend_task,
|
|
||||||
udp_task,
|
|
||||||
resolver_task
|
|
||||||
);
|
|
||||||
|
|
||||||
ping_task.abort();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ pub enum CaptureEvent {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
backend: Option<CaptureBackend>,
|
backend: Option<CaptureBackend>,
|
||||||
server: Server,
|
server: Server,
|
||||||
sender_tx: Sender<(Event, SocketAddr)>,
|
udp_send: Sender<(Event, SocketAddr)>,
|
||||||
frontend_tx: Sender<FrontendEvent>,
|
frontend_tx: Sender<FrontendEvent>,
|
||||||
timer_notify: Arc<Notify>,
|
notify_ping: Arc<Notify>,
|
||||||
release_bind: Vec<scancode::Linux>,
|
release_bind: Vec<scancode::Linux>,
|
||||||
cancellation_token: CancellationToken,
|
cancellation_token: CancellationToken,
|
||||||
notify_capture: Arc<Notify>,
|
notify_capture: Arc<Notify>,
|
||||||
@@ -60,10 +60,10 @@ pub fn new(
|
|||||||
let task = tokio::task::spawn_local(capture_task(
|
let task = tokio::task::spawn_local(capture_task(
|
||||||
backend,
|
backend,
|
||||||
server,
|
server,
|
||||||
sender_tx,
|
udp_send,
|
||||||
rx,
|
rx,
|
||||||
frontend_tx,
|
frontend_tx,
|
||||||
timer_notify,
|
notify_ping,
|
||||||
release_bind,
|
release_bind,
|
||||||
cancellation_token,
|
cancellation_token,
|
||||||
notify_capture,
|
notify_capture,
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ async fn do_emulation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// release potentially still pressed keys
|
// release potentially still pressed keys
|
||||||
release_all_keys(&server, &mut emulation).await?;
|
release_all_keys(server, &mut emulation).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,12 @@ pub fn new(
|
|||||||
cancellation_token: CancellationToken,
|
cancellation_token: CancellationToken,
|
||||||
) -> JoinHandle<()> {
|
) -> JoinHandle<()> {
|
||||||
// timer task
|
// timer task
|
||||||
let ping_task = tokio::task::spawn_local(async move {
|
tokio::task::spawn_local(async move {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = cancellation_token.cancelled() => {}
|
_ = cancellation_token.cancelled() => {}
|
||||||
_ = ping_task(server, sender_ch, emulate_notify, capture_notify, timer_notify) => {}
|
_ = ping_task(server, sender_ch, emulate_notify, capture_notify, timer_notify) => {}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
ping_task
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ping_task(
|
async fn ping_task(
|
||||||
|
|||||||
Reference in New Issue
Block a user