zola/components/utils/src/net.rs
Vincent Prouillet b892c07ed3 Don't hardcode the ws port
Closes #282
2018-06-25 17:59:04 +02:00

15 lines
290 B
Rust

use std::net::TcpListener;
pub fn get_available_port() -> Option<u16> {
(1000..9000)
.find(|port| port_is_available(*port))
}
fn port_is_available(port: u16) -> bool {
match TcpListener::bind(("127.0.0.1", port)) {
Ok(_) => true,
Err(_) => false,
}
}