From 98fa3207bb097cf81da5b200a2944cf6056ccff1 Mon Sep 17 00:00:00 2001 From: Shautvast Date: Mon, 9 Feb 2026 19:52:44 +0100 Subject: [PATCH] #11 make it multi threaded --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4c0a7f4..301dfd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use log::info; use std::io::{Read, Write}; use std::net::{TcpListener, TcpStream}; +use std::thread; static GET: &'static [u8] = b"GET / HTTP/1.1\r\n"; @@ -8,7 +9,10 @@ fn main() -> std::io::Result<()> { env_logger::init(); let listener = TcpListener::bind("127.0.0.1:7878")?; for stream in listener.incoming() { - handle_connection(stream?)?; + let stream = stream?; + thread::spawn(|| { + handle_connection(stream).unwrap(); + }); } Ok(()) }