Quickfix: Clear pool if stuck for too long

This commit is contained in:
p11 2023-08-15 23:14:13 +02:00
parent a9f605cf0e
commit 85e4cb3e4a

View File

@ -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);
}
}