Connection handling not a method of context anymore

This commit is contained in:
p11 2023-09-16 16:34:53 +02:00
parent 337ca0149e
commit 34b8307426

View File

@ -52,7 +52,7 @@ fn main() {
}
}
context.handle_connection(&path, stream, &pool);
handle_connection(&mut context, &path, stream, &pool);
}
}
@ -133,8 +133,7 @@ struct Context {
infos: HashMap<Box<str>, Arc<Mutex<SiteInfo>>>,
}
impl Context {
fn handle_connection(&mut self, path: &Path, mut stream: TcpStream, pool: &ThreadPool) {
fn handle_connection(context: &mut Context, path: &Path, mut stream: TcpStream, pool: &ThreadPool) {
let Some(request) = Request::from(&stream) else {
eprintln!("Invalid request!");
return;
@ -211,7 +210,7 @@ impl Context {
}
use Entry::*;
let info = match self.infos.entry(relative_path.clone().into_boxed_str()) {
let info = match context.infos.entry(relative_path.clone().into_boxed_str()) {
Occupied(o) => o.get().clone(),
Vacant(v) => v
.insert(Arc::new(Mutex::new(
@ -239,7 +238,6 @@ impl Context {
)
});
}
}
fn reply_image(mut stream: TcpStream, relative_path: &str, mut path: PathBuf) {
let Some((_, ending)) = relative_path.rsplit_once('.') else {