fix for 'port already in use' not being implemented, causing panic

This commit is contained in:
2026-03-15 19:17:47 +01:00
parent c061763538
commit 2b62b9c272
2 changed files with 13 additions and 4 deletions

View File

@@ -22,5 +22,7 @@ fn main() {
std::process::exit(1); std::process::exit(1);
} }
server::run(root, port); if let Err(_) = server::run(root, port) {
log_error!("Port {} already in use!", port);
}
} }

View File

@@ -7,9 +7,14 @@ use tiny_http::Server;
use crate::router; use crate::router;
use crate::response; use crate::response;
pub fn run(root: Arc<PathBuf>, port: u16) { pub fn run(
let addr = format!("0.0.0.0:{}", port); root: Arc<PathBuf>,
let server = Arc::new(Server::http(&addr).expect("Failed to start server")); port: u16
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let addr = format!("0.0.0.0:{}", port); // serve localhost
let server = Arc::new(Server::http(&addr)?);
let pool = ThreadPool::new(num_cpus()); let pool = ThreadPool::new(num_cpus());
log_info!("Serving '{}' on http://{}", root.display(), addr); log_info!("Serving '{}' on http://{}", root.display(), addr);
@@ -34,6 +39,8 @@ pub fn run(root: Arc<PathBuf>, port: u16) {
} }
}); });
} }
Ok(())
} }
fn num_cpus() -> usize { fn num_cpus() -> usize {