Skip to content

Commit

Permalink
replace CLI with constant for sv1 example
Browse files Browse the repository at this point in the history
  • Loading branch information
plebhash committed Jan 30, 2025
1 parent 2dadb31 commit d540882
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions protocols/v1/examples/client_and_server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
convert::{TryFrom, TryInto},
env,
io::{BufRead, BufReader, Write},
net::{SocketAddr, TcpListener, TcpStream},
process::exit,
Expand All @@ -10,6 +9,7 @@ use std::{
};

const ADDR: &str = "127.0.0.1:0";
const TEST_DURATION: i32 = 30;

type Receiver<T> = mpsc::Receiver<T>;
type Sender<T> = mpsc::Sender<T>;
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'a> Server<'a> {
{
let cloned = Arc::clone(&server_arc);
thread::spawn(move || {
let mut run_time = Self::get_runtime();
let mut run_time = TEST_DURATION;
loop {
let notify_time = 5;
if let Ok(mut self_) = cloned.try_lock() {
Expand All @@ -178,7 +178,7 @@ impl<'a> Server<'a> {
run_time -= notify_time as i32;

if run_time <= 0 {
println!("Test Success - ran for {} seconds", Server::get_runtime());
println!("Test Success - ran for {} seconds", TEST_DURATION);
exit(0)
}
}
Expand All @@ -188,15 +188,6 @@ impl<'a> Server<'a> {
server_arc
}

fn get_runtime() -> i32 {
let args: Vec<String> = env::args().collect();
if args.len() > 1 {
args[1].parse::<i32>().unwrap()
} else {
i32::MAX
}
}

fn handle_message(
&mut self,
_message: json_rpc::Message,
Expand Down

0 comments on commit d540882

Please sign in to comment.