mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-20 19:50:55 +03:00
use local-channel instead of tokio sync channel (#179)
this avoids the mutex overhead in tokio
This commit is contained in:
committed by
GitHub
parent
19c2c4327f
commit
e7a1d72149
@@ -1,12 +1,9 @@
|
||||
use futures::StreamExt;
|
||||
use lan_mouse_proto::ProtoEvent;
|
||||
use local_channel::mpsc::{Receiver, Sender};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use tokio::{
|
||||
process::Command,
|
||||
sync::mpsc::{Receiver, Sender},
|
||||
task::JoinHandle,
|
||||
};
|
||||
use tokio::{process::Command, task::JoinHandle};
|
||||
|
||||
use input_capture::{
|
||||
self, CaptureError, CaptureEvent, CaptureHandle, InputCapture, InputCaptureError, Position,
|
||||
@@ -161,7 +158,7 @@ async fn handle_capture_event(
|
||||
/* released capture */
|
||||
State::Receiving => ProtoEvent::Leave(0),
|
||||
};
|
||||
sender_tx.send((event, addr)).await.expect("sender closed");
|
||||
sender_tx.send((event, addr)).expect("sender closed");
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use local_channel::mpsc::{Receiver, Sender};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use lan_mouse_proto::ProtoEvent;
|
||||
use tokio::{
|
||||
sync::mpsc::{Receiver, Sender},
|
||||
task::JoinHandle,
|
||||
};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::{
|
||||
client::{ClientHandle, ClientManager},
|
||||
@@ -140,7 +138,7 @@ async fn handle_incoming_event(
|
||||
match (event, addr) {
|
||||
(ProtoEvent::Pong, _) => { /* ignore pong events */ }
|
||||
(ProtoEvent::Ping, addr) => {
|
||||
let _ = sender_tx.send((ProtoEvent::Pong, addr)).await;
|
||||
let _ = sender_tx.send((ProtoEvent::Pong, addr));
|
||||
}
|
||||
(ProtoEvent::Leave(_), _) => emulate.release_keys(handle).await?,
|
||||
(ProtoEvent::Ack(_), _) => server.set_state(State::Sending),
|
||||
@@ -148,7 +146,6 @@ async fn handle_incoming_event(
|
||||
server.set_state(State::Receiving);
|
||||
sender_tx
|
||||
.send((ProtoEvent::Ack(0), addr))
|
||||
.await
|
||||
.expect("no channel")
|
||||
}
|
||||
(ProtoEvent::Input(e), _) => {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
use local_channel::mpsc::{Receiver, Sender};
|
||||
use std::{io, net::SocketAddr};
|
||||
|
||||
use thiserror::Error;
|
||||
use tokio::{
|
||||
net::UdpSocket,
|
||||
sync::mpsc::{Receiver, Sender},
|
||||
task::JoinHandle,
|
||||
};
|
||||
use tokio::{net::UdpSocket, task::JoinHandle};
|
||||
|
||||
use super::Server;
|
||||
use lan_mouse_proto::{ProtoEvent, ProtocolError};
|
||||
@@ -65,7 +62,7 @@ async fn udp_receiver(
|
||||
) {
|
||||
loop {
|
||||
let event = receive_event(socket).await;
|
||||
receiver_tx.send(event).await.expect("channel closed");
|
||||
receiver_tx.send(event).expect("channel closed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use std::{net::SocketAddr, time::Duration};
|
||||
|
||||
use lan_mouse_proto::ProtoEvent;
|
||||
use tokio::{sync::mpsc::Sender, task::JoinHandle};
|
||||
use local_channel::mpsc::Sender;
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::client::ClientHandle;
|
||||
|
||||
@@ -85,7 +86,7 @@ async fn ping_task(
|
||||
|
||||
// ping clients
|
||||
for addr in ping_addrs {
|
||||
if sender_ch.send((ProtoEvent::Ping, addr)).await.is_err() {
|
||||
if sender_ch.send((ProtoEvent::Ping, addr)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -122,14 +123,14 @@ async fn ping_task(
|
||||
if receiving {
|
||||
for h in unresponsive_clients {
|
||||
log::warn!("device not responding, releasing keys!");
|
||||
let _ = emulate_notify.send(EmulationRequest::ReleaseKeys(h)).await;
|
||||
let _ = emulate_notify.send(EmulationRequest::ReleaseKeys(h));
|
||||
}
|
||||
} else {
|
||||
// release pointer if the active client has not responded
|
||||
if !unresponsive_clients.is_empty() {
|
||||
log::warn!("client not responding, releasing pointer!");
|
||||
server.state.replace(State::Receiving);
|
||||
let _ = capture_notify.send(CaptureRequest::Release).await;
|
||||
let _ = capture_notify.send(CaptureRequest::Release);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user