Skip to content

Commit

Permalink
Daemon: improve read/send loop
Browse files Browse the repository at this point in the history
With this change the daemon will send serialized input records in
"batches". Instead of sending all available records in a row it will
send N in a row, than wait for 1 millisecond, then send N more (if
available).
While this doesn't fix the copy/paste problem it does already improve
the situation.
  • Loading branch information
whme committed Aug 9, 2023
1 parent d97b2e7 commit fa162bd
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
sync::{Arc, Mutex},
time::Duration,
};
use std::{thread, time};

use crate::{
serde::{serialization::Serialize, SERIALIZED_INPUT_RECORD_0_LENGTH},
Expand Down Expand Up @@ -106,15 +107,24 @@ impl Daemon {
}
});

let mut transmitted_records = 0;
loop {
if transmitted_records == SENDER_CAPACITY - 1 {
thread::sleep(time::Duration::from_millis(1));
transmitted_records = 0;
}
let input_record = read_keyboard_input();
sender
.send(
input_record.serialize().as_mut_vec()[..]
.try_into()
.unwrap(),
)
.unwrap();
match sender.send(
input_record.serialize().as_mut_vec()[..]
.try_into()
.unwrap(),
) {
Ok(_) => {}
Err(_) => {
thread::sleep(time::Duration::from_millis(1));
}
}
transmitted_records += 1;
}
}

Expand Down

0 comments on commit fa162bd

Please sign in to comment.