fix exception if host isn't resolvable
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -25,14 +25,16 @@ fn upload_config(h: &Host) -> Result<String, String> {
|
|||||||
let content = h.content.lock().unwrap();
|
let content = h.content.lock().unwrap();
|
||||||
let connection_string = format!("{}@{}", username, host);
|
let connection_string = format!("{}@{}", username, host);
|
||||||
|
|
||||||
let addr: SocketAddr = format!("{}:{}", host, port)
|
let addr: SocketAddr = match format!("{}:{}", host, port).to_socket_addrs() {
|
||||||
.to_socket_addrs()
|
Ok(mut addrs) => addrs.nth(0).expect(format!("Invalid host/port in `{}:{}`", host, port).as_str()),
|
||||||
.unwrap().nth(0)
|
_ => return Err(connection_string)
|
||||||
.expect(format!("Invalid host/port in `{}:{}`", host, port).as_str());
|
};
|
||||||
let tcp: TcpStream = match TcpStream::connect_timeout(&addr, Duration::from_secs(1)) {
|
|
||||||
|
let tcp: TcpStream = match TcpStream::connect_timeout(&addr, Duration::from_secs(3)) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return Err(connection_string)
|
Err(_) => return Err(connection_string)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut sess = Session::new().unwrap();
|
let mut sess = Session::new().unwrap();
|
||||||
|
|
||||||
sess.set_tcp_stream(tcp);
|
sess.set_tcp_stream(tcp);
|
||||||
|
|||||||
Reference in New Issue
Block a user