accept other socket errors, ignore unless out of tries (#1835)

This commit is contained in:
Rob Walker 2018-11-15 15:49:37 -08:00 committed by GitHub
parent 96e03eca14
commit d3e521f70e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -126,7 +126,7 @@ pub fn bind_in_range(range: (u16, u16)) -> io::Result<(u16, UdpSocket)> {
break Result::Ok((sock.local_addr().unwrap().port(), sock));
}
Err(err) => {
if err.kind() != io::ErrorKind::AddrInUse || tries_left == 0 {
if tries_left == 0 {
return Err(err);
}
}
@ -170,6 +170,8 @@ pub fn find_available_port_in_range(range: (u16, u16)) -> io::Result<u16> {
let mut tries_left = end - start;
let mut rand_port = thread_rng().gen_range(start, end);
loop {
eprintln!("trying port {}", rand_port);
match TcpListener::bind(SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
rand_port,
@ -178,7 +180,7 @@ pub fn find_available_port_in_range(range: (u16, u16)) -> io::Result<u16> {
break Ok(rand_port);
}
Err(err) => {
if err.kind() != io::ErrorKind::AddrInUse || tries_left == 0 {
if tries_left == 0 {
return Err(err);
}
}