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 27, 2025
1 parent 96ae4a5 commit baa0465
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,7 +1,6 @@
use std::net::{TcpListener, TcpStream};
use std::convert::{TryFrom, TryInto};
use std::{
env,
io::{BufRead, BufReader, Write},
net::SocketAddr,
process::exit,
Expand All @@ -12,6 +11,7 @@ use std::{
use std::time::SystemTime;

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 @@ -167,7 +167,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 @@ -182,7 +182,7 @@ impl<'a> Server<'a> {
if run_time <= 0 {
println!(
"Test Success - ran for {} seconds",
Server::get_runtime()
TEST_DURATION
);
exit(0)
}
Expand All @@ -193,15 +193,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 baa0465

Please sign in to comment.