added threading functionality

This commit is contained in:
Mitchell 2020-04-11 15:43:49 +00:00
parent 5ca31a2b04
commit 8a674dca94
1 changed files with 5 additions and 1 deletions

View File

@ -7,13 +7,15 @@ fn main(){
let listener = TcpListener::bind("127.0.0.1:6001").unwrap();
let pool = ThreadPool::new(4);
for stream in listener.incoming(){
for stream in listener.incoming() {
let stream = stream.unwrap();
pool.execute(|| {
handle_connection(stream);
});
}
println!("Shutting down.");
}
fn handle_connection(mut stream: TcpStream){
@ -22,6 +24,8 @@ fn handle_connection(mut stream: TcpStream){
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
//stream.write(response.as_bytes()).unwrap();
//stream.flush().unwrap();
}