aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-02 21:55:19 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-02 21:55:19 -0400
commit0b058f570e71a3eaa1314a947fdff3d88193a63f (patch)
tree0bcb7d79e68722c9a63501e6f2fe478aae9d37cf /src/client.rs
parentc98d8a044308e3cde1de4945dbb7f5ee62ab52a5 (diff)
downloaducp-0b058f570e71a3eaa1314a947fdff3d88193a63f.tar.gz
ucp-0b058f570e71a3eaa1314a947fdff3d88193a63f.zip
more improvements to error handling
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/client.rs b/src/client.rs
index acc3425..f26c35d 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -39,15 +39,15 @@ pub fn run_client(host: &str, local_file: &str, remote_file: &str, remote_is_dir
let ssh_output = ssh_cmd.output().expect("couldn't get SSH sub-process output");
if !ssh_output.status.success() {
- println!("Error on remote end: {}", String::from_utf8_lossy(&ssh_output.stderr));
- exit(-1);
+ return Err(format!("Error on remote end: {}",
+ String::from_utf8_lossy(&ssh_output.stderr)));
}
let reply = String::from_utf8_lossy(&ssh_output.stdout);
- println!("SSH reply: {}", reply);
+ //println!("SSH reply: {}", reply);
let words: Vec<&str> = reply.split_whitespace().collect();
if words.len() != 7 || words[0] != "UCP" || words[1] != "CONNECT" {
- panic!("Unexpected data via SSH pipe (TCP)");
+ return Err("Unexpected data via SSH pipe (TCP)".to_string());
}
let remote_host = words[2];
let remote_port = words[3].parse::<u16>().expect("failed to parse remote port number");
@@ -64,7 +64,10 @@ pub fn run_client(host: &str, local_file: &str, remote_file: &str, remote_is_dir
let addr = net::IpAddr::from_str(remote_host).unwrap();
let mut socket = UdtSocket::new(udt::SocketFamily::AFInet, udt::SocketType::Stream).unwrap();
- socket.connect(net::SocketAddr::new(addr, remote_port)).unwrap();;
+ match socket.connect(net::SocketAddr::new(addr, remote_port)) {
+ Ok(_) => { println!("Connected."); },
+ Err(e) => { return Err(e.err_msg); },
+ };
let mut stream: UdtStream = UdtStream::new(socket);
if !no_crypto {