From f343596e1f526c252c0b0b2986222b8afd65dd28 Mon Sep 17 00:00:00 2001 From: Alex van de Sandt Date: Fri, 12 Apr 2019 15:40:42 -0400 Subject: [PATCH] Extract writing to client to function --- candid_server/src/client_handler.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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(()) +} -- 2.51.2