// Find a port in the given range that is available for both TCP and UDP
Find a port in the given range that is available for both TCP and UDP
Find a port in the given range that is available for both TCP and UDP
pub fn bind_common_in_range(range: PortRange) -> io::Result<(u16, (UdpSocket, TcpListener))> {
    let (start, end) = range;
    let mut tries_left = end - start;
    let mut rand_port = thread_rng().gen_range(start, end);
    loop {
        match bind_common(rand_port, false) {
            Ok((sock, listener)) => {
                break Result::Ok((sock.local_addr().unwrap().port(), (sock, listener)));
            }
            Err(err) => {
                if tries_left == 0 {
                    return Err(err);
                }
            }
        }
        rand_port += 1;
        if rand_port == end {
            rand_port = start;
        }
        tries_left -= 1;
    }
}
pub fn bind_common_in_range ( range : PortRange ) -> io :: Result < ( u16 , ( UdpSocket , TcpListener ) ) > { let ( start , end ) = range ; let mut tries_left = end - start ; let mut rand_port = thread_rng ( ) . gen_range ( start , end ) ; loop { match bind_common ( rand_port , false ) { Ok ( ( sock , listener ) ) => { break Result :: Ok ( ( sock . local_addr ( ) . unwrap ( ) . port ( ) , ( sock , listener ) ) ) ; } Err ( err ) => { if tries_left == 0 { return Err ( err ) ; } } } rand_port += 1 ; if rand_port == end { rand_port = start ; } tries_left -= 1 ; } }
Find a port in the given range that is available for both TCP and UDP
Find a port in the given range that is available for both TCP and UDP
range
PortRange