|
@@ -42,10 +42,11 @@ fn malformed_packet(err: std::io::Error) {
|
|
|
|
|
|
fn handle(mut stream: tcp::TcpStream) {
|
|
|
let _ = stream.write(&"go fuck you kthxbye".as_bytes());
|
|
|
- let _ = stream.local_addr()
|
|
|
- .map(|addr|
|
|
|
- info!("somebody opened a tcp connection to {}:{}", addr.ip(), addr.port()))
|
|
|
- .map_err(malformed_packet);
|
|
|
+ match stream.local_addr() {
|
|
|
+ Ok(addr) =>
|
|
|
+ info!("somebody opened a tcp connection to {}:{}", addr.ip(), addr.port()),
|
|
|
+ Err(err) => malformed_packet(err),
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
fn main() {
|
|
@@ -80,11 +81,13 @@ fn main() {
|
|
|
for event in events.iter() {
|
|
|
match (event.token(), event.kind().is_readable()) {
|
|
|
(SERVER, true) => {
|
|
|
- let (stream, _) = server.accept().unwrap();
|
|
|
- handle(stream);
|
|
|
- }
|
|
|
+ match server.accept() {
|
|
|
+ Err(err) => malformed_packet(err),
|
|
|
+ Ok((stream, _)) => handle(stream),
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- _ => {
|
|
|
+ _ => {
|
|
|
info!("something happened: {:?}", event.kind());
|
|
|
// unreachable!(),
|
|
|
}
|