Fix handling client socket errors

This commit is contained in:
Kevin Cotugno 2018-11-30 11:24:57 -08:00
parent 2c106cdd26
commit 5bc1ecb70e

View File

@ -76,18 +76,14 @@ fn parse_ip(host: &str) -> Result<IpAddr, String> {
} }
fn do_request(dest: SocketAddr, socket: &UdpSocket) -> Result<IpAddr, String> { fn do_request(dest: SocketAddr, socket: &UdpSocket) -> Result<IpAddr, String> {
if socket.connect(dest).is_err() { match socket.connect(dest) {
return Err(format!( Ok(_) => (),
"Unable to connect: {}", Err(err) => return Err(format!("Unable to connect: {}", err)),
socket.take_error().unwrap().unwrap()
));
} }
if socket.send(&[]).is_err() { match socket.send(&[]) {
return Err(format!( Ok(_) => (),
"Failed to send request: {}", Err(err) => return Err(format!("Failed to send request: {}", err)),
socket.take_error().unwrap().unwrap()
));
} }
let mut buf = [0; 1024]; let mut buf = [0; 1024];