diff --git a/candid_server/src/client_handler.rs b/candid_server/src/client_handler.rs index 5812531..bf4b08f 100644 --- a/candid_server/src/client_handler.rs +++ b/candid_server/src/client_handler.rs @@ -22,12 +22,9 @@ pub fn new_client_handler( let frame = can_reader.recv().unwrap(); // Relay to the client - match connection.write_fmt(format_args!("{:X}\n", frame)) { - Ok(_) => {} - Err(_) => { - println!("Connection to client {:?} dropped.", ip); - break; - } + if let Err(_) = write_frame(&mut connection, frame) { + println!("Connection to client {:?} dropped.", ip); + break; } } }); @@ -64,3 +61,8 @@ pub fn new_client_handler( (tx_handle, rx_handle) } + +fn write_frame(connection: &mut TcpStream, frame: CANFrame) -> Result<(), std::io::Error> { + connection.write_fmt(format_args!("{:X}\n", frame))?; + Ok(()) +}