(preferred: u16, bind: IpAddr)
| 2435 | } |
| 2436 | |
| 2437 | fn choose_available_service_port_for_bind(preferred: u16, bind: IpAddr) -> anyhow::Result<u16> { |
| 2438 | let start = preferred.max(1024); |
| 2439 | for port in start..=u16::MAX { |
| 2440 | if port_available(bind, port) { |
| 2441 | return Ok(port); |
| 2442 | } |
| 2443 | } |
| 2444 | anyhow::bail!("No available SimDeck service port at or above {start}") |
| 2445 | } |
| 2446 | |
| 2447 | fn port_available(bind: IpAddr, port: u16) -> bool { |
| 2448 | if bind.is_unspecified() && TcpListener::bind((Ipv4Addr::LOCALHOST, port)).is_err() { |
no test coverage detected