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> {
if socket.connect(dest).is_err() {
return Err(format!(
"Unable to connect: {}",
socket.take_error().unwrap().unwrap()
));
match socket.connect(dest) {
Ok(_) => (),
Err(err) => return Err(format!("Unable to connect: {}", err)),
}
if socket.send(&[]).is_err() {
return Err(format!(
"Failed to send request: {}",
socket.take_error().unwrap().unwrap()
));
match socket.send(&[]) {
Ok(_) => (),
Err(err) => return Err(format!("Failed to send request: {}", err)),
}
let mut buf = [0; 1024];