diff --git a/src/main.rs b/src/main.rs index 801d817..a73707e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ use std::{ net::{TcpListener, TcpStream}, path::{Path, PathBuf}, sync::{Arc, Mutex}, + thread, + time::Duration, }; use data_stream::{ @@ -27,7 +29,7 @@ fn main() { }; let mut context = Context::default(); - let pool = ThreadPool::new(4); + let mut pool = ThreadPool::new(4); let mut args = env::args(); args.next(); @@ -43,6 +45,13 @@ fn main() { continue; }; + if pool.active_count() == pool.max_count() { + thread::sleep(Duration::from_secs(1)); + if pool.active_count() == pool.max_count() { + pool = ThreadPool::new(pool.max_count()) + } + } + context.handle_connection(&path, stream, &pool); } }