add rate limit sleep
This commit is contained in:
parent
71d5949588
commit
9a2d4c2931
2 changed files with 5 additions and 6 deletions
|
@ -21,6 +21,7 @@ pub struct ClientParams<'a> {
|
||||||
pub modem_port: Option<&'a str>,
|
pub modem_port: Option<&'a str>,
|
||||||
pub modem_baud: Option<u32>,
|
pub modem_baud: Option<u32>,
|
||||||
pub modem_init: Option<&'a str>,
|
pub modem_init: Option<&'a str>,
|
||||||
|
pub rate_limit_sleep: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect(params: &ClientParams) -> Connection {
|
fn connect(params: &ClientParams) -> Connection {
|
||||||
|
@ -101,6 +102,7 @@ pub fn client(params: ClientParams) {
|
||||||
let mut id = 0;
|
let mut id = 0;
|
||||||
let mut last_keep_alive = SystemTime::now();
|
let mut last_keep_alive = SystemTime::now();
|
||||||
loop {
|
loop {
|
||||||
|
thread::sleep(Duration::from_millis(params.rate_limit_sleep));
|
||||||
let mut did_anything = false;
|
let mut did_anything = false;
|
||||||
|
|
||||||
if last_keep_alive.elapsed().unwrap().as_secs() >= 60 {
|
if last_keep_alive.elapsed().unwrap().as_secs() >= 60 {
|
||||||
|
|
|
@ -4,21 +4,18 @@ use revpfw3::{client, server, ClientParams};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<_> = env::args().skip(1).collect();
|
let args: Vec<_> = env::args().skip(1).collect();
|
||||||
if (6..=10).contains(&args.len()) && args[0] == "client" {
|
if (6..=11).contains(&args.len()) && args[0] == "client" {
|
||||||
client(ClientParams {
|
client(ClientParams {
|
||||||
server_ip: &args[1],
|
server_ip: &args[1],
|
||||||
server_port: args[2].parse().unwrap(),
|
server_port: args[2].parse().unwrap(),
|
||||||
dest_ip: &args[3],
|
dest_ip: &args[3],
|
||||||
dest_port: args[4].parse().unwrap(),
|
dest_port: args[4].parse().unwrap(),
|
||||||
key: &args[5],
|
key: &args[5],
|
||||||
sleep_delay_ms: if args.len() == 7 {
|
sleep_delay_ms: args.get(6).map(|x| x.parse().unwrap()).unwrap_or(1),
|
||||||
args[6].parse().unwrap()
|
|
||||||
} else {
|
|
||||||
1
|
|
||||||
},
|
|
||||||
modem_port: args.get(7).map(|x| x.as_str()),
|
modem_port: args.get(7).map(|x| x.as_str()),
|
||||||
modem_baud: args.get(8).map(|x| x.parse().unwrap()),
|
modem_baud: args.get(8).map(|x| x.parse().unwrap()),
|
||||||
modem_init: args.get(9).map(|x| x.as_str()),
|
modem_init: args.get(9).map(|x| x.as_str()),
|
||||||
|
rate_limit_sleep: args.get(10).map(|x| x.parse().unwrap()).unwrap_or(0),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (3..=4).contains(&args.len()) && args[0] == "server" {
|
if (3..=4).contains(&args.len()) && args[0] == "server" {
|
||||||
|
|
Loading…
Add table
Reference in a new issue