Improve error handling for incoming TCP connections

This commit is contained in:
William Brawner 2022-07-24 22:41:02 -06:00
parent 8f8f152f5f
commit f481dcfbf7

View file

@ -15,10 +15,12 @@ fn main() {
let listener = TcpListener::bind("127.0.0.1:4762").unwrap(); let listener = TcpListener::bind("127.0.0.1:4762").unwrap();
let pool = ThreadPool::new(4); let pool = ThreadPool::new(4);
for stream in listener.incoming() { for stream in listener.incoming() {
let stream = stream.unwrap(); match stream {
pool.execute(|| { Ok(s) => pool.execute(|| {
handle_connection(stream); handle_connection(s);
}); }),
Err(e) => println!("invalid stream: {:?}\n", e),
}
} }
} }