Skip to content

Commit

Permalink
Don't start if udp port is really closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Jun 3, 2020
1 parent 69d90b5 commit fdd0d05
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions net-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn verify_reachable_ports(
return ok;
}

for _udp_retries in 0..5 {
for udp_remaining_retry in (0_usize..5).rev() {
// Wait for a datagram to arrive at each UDP port
for udp_socket in udp_sockets {
let port = udp_socket.local_addr().unwrap().port();
Expand Down Expand Up @@ -179,14 +179,18 @@ pub fn verify_reachable_ports(
if ok {
break;
}
ok = true;

// Might have lost a UDP packet, retry a couple times
let _ = ip_echo_server_request(
ip_echo_server_addr,
IpEchoServerMessage::new(&[], &udp_ports),
)
.map_err(|err| warn!("ip_echo_server request failed: {}", err));

if udp_remaining_retry > 0 {
// Might have lost a UDP packet, retry a couple times
ok = true;
let _ = ip_echo_server_request(
ip_echo_server_addr,
IpEchoServerMessage::new(&[], &udp_ports),
)
.map_err(|err| warn!("ip_echo_server request failed: {}", err));
} else {
error!("maximum retry count is reached....");
}
}

ok
Expand Down

0 comments on commit fdd0d05

Please sign in to comment.