Skip to content

Commit

Permalink
Merge pull request #93 from genonullfree/listener-error-printing
Browse files Browse the repository at this point in the history
Listener error printing
  • Loading branch information
genonullfree authored Oct 31, 2022
2 parents f756312 + d0f0421 commit ca86816
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "teleporter"
version = "0.10.0"
version = "0.10.1"
authors = ["geno nullfree <[email protected]>"]
license = "BSD-3-Clause"
description = "A small utility to send files quickly from point A to point B"
Expand Down
14 changes: 8 additions & 6 deletions src/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ pub fn run(opt: ListenOpt) -> Result<(), TeleportError> {
// Receive connections in recv function
let recv_list_clone = Arc::clone(&recv_list);
thread::spawn(move || {
handle_connection(s, recv_list_clone, args).unwrap();
if let Err(e) = handle_connection(s, &recv_list_clone, args) {
println!("Error: {:?}", e);
}
let recv_list = recv_list_clone.lock().unwrap();
print_list(&recv_list);
});
}

Expand Down Expand Up @@ -72,13 +76,11 @@ fn print_list(list: &MutexGuard<Vec<String>>) {
fn rm_filename_from_list(filename: &str, list: &Arc<Mutex<Vec<String>>>) {
let mut recv_data = list.lock().unwrap();
recv_data.retain(|x| x != filename);
print_list(&recv_data);
drop(recv_data);
}

fn handle_connection(
mut stream: TcpStream,
recv_list: Arc<Mutex<Vec<String>>>,
recv_list: &Arc<Mutex<Vec<String>>>,
opt: ListenOpt,
) -> Result<(), TeleportError> {
let start_time = Instant::now();
Expand Down Expand Up @@ -230,7 +232,7 @@ fn handle_connection(
"Connection closed (reason: {:?}). Aborted {} transfer.",
e, &filename
);
rm_filename_from_list(&filename, &recv_list);
rm_filename_from_list(&filename, recv_list);
return Ok(());
}
}
Expand Down Expand Up @@ -295,7 +297,7 @@ fn handle_connection(
}
}

rm_filename_from_list(&filename, &recv_list);
rm_filename_from_list(&filename, recv_list);

Ok(())
}

0 comments on commit ca86816

Please sign in to comment.