Error messages, less unwrap
This commit is contained in:
parent
f16343a93a
commit
710df5f6bc
@ -19,9 +19,15 @@ fn main() {
|
|||||||
args.next();
|
args.next();
|
||||||
let address = args.next().unwrap_or("127.0.0.1:8080".to_string());
|
let address = args.next().unwrap_or("127.0.0.1:8080".to_string());
|
||||||
let listener = TcpListener::bind(address).unwrap();
|
let listener = TcpListener::bind(address).unwrap();
|
||||||
|
eprintln!("Strated server!");
|
||||||
|
|
||||||
for stream in listener.incoming() {
|
for stream in listener.incoming() {
|
||||||
let stream = stream.unwrap();
|
eprintln!("New connection!");
|
||||||
|
|
||||||
|
let Ok(stream) = stream else {
|
||||||
|
eprintln!("Connection failed!");
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
context.handle_connection(stream);
|
context.handle_connection(stream);
|
||||||
}
|
}
|
||||||
@ -45,6 +51,7 @@ struct Context {
|
|||||||
impl Context {
|
impl Context {
|
||||||
fn handle_connection(&mut self, mut stream: TcpStream) {
|
fn handle_connection(&mut self, mut stream: TcpStream) {
|
||||||
let Some(request) = Request::from(&stream) else {
|
let Some(request) = Request::from(&stream) else {
|
||||||
|
eprintln!("Invalid request!");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user