added threading functionality
This commit is contained in:
parent
5ca31a2b04
commit
8a674dca94
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue