diff --git a/candid_client/src/candid_connection.rs b/candid_client/src/candid_connection.rs index 453cf35..25fd54c 100644 --- a/candid_client/src/candid_connection.rs +++ b/candid_client/src/candid_connection.rs @@ -38,7 +38,7 @@ impl CandidConnection { /// Sends a frame to the server pub fn write_frame(&mut self, frame: Frame) -> Result<(), std::io::Error> { self.write_stream.write_u32::(frame.id)?; - self.write_stream.write(&frame.data)?; + self.write_stream.write_all(&frame.data)?; self.write_stream.flush().unwrap(); Ok(()) } diff --git a/candid_server/src/can_reader.rs b/candid_server/src/can_reader.rs index 46a911a..d4f5cb1 100644 --- a/candid_server/src/can_reader.rs +++ b/candid_server/src/can_reader.rs @@ -28,7 +28,7 @@ impl CANReader { // Write it to each client let mut dropped_clients = Vec::new(); for (i, client) in clients.lock().unwrap().iter().enumerate() { - client.send(frame.clone()).unwrap_or_else(|_| { + client.send(frame).unwrap_or_else(|_| { // Indicate that this client's connection has been dropped dropped_clients.push(i); }); @@ -46,7 +46,7 @@ impl CANReader { /// Registers a client with this `CANReader` pub fn add_client(&self, channel: mpsc::Sender) { - &self.clients.lock().unwrap().push(channel); + self.clients.lock().unwrap().push(channel); } /// Returns a copy of the underlying `CANsocket` diff --git a/candid_server/src/client_handler.rs b/candid_server/src/client_handler.rs index 3e4abd3..5b0e229 100644 --- a/candid_server/src/client_handler.rs +++ b/candid_server/src/client_handler.rs @@ -24,7 +24,7 @@ pub fn new_client_handler( let frame = can_reader.recv().unwrap(); // Relay to the client - if let Err(_) = write_frame(&mut connection, frame) { + if send_frame(&mut connection, frame).is_err() { println!("Connection to client {:?} dropped.", ip); break; } @@ -50,7 +50,7 @@ pub fn new_client_handler( } let mut data = [0 as u8; 8]; - if let Err(_) = connection.read_exact(&mut data) { + if connection.read_exact(&mut data).is_err() { println!("Connection to client {:?} dropped.", ip); break; } @@ -64,9 +64,9 @@ pub fn new_client_handler( (tx_handle, rx_handle) } -fn write_frame(connection: &mut TcpStream, frame: CANFrame) -> Result<(), std::io::Error> { +fn send_frame(connection: &mut TcpStream, frame: CANFrame) -> Result<(), std::io::Error> { connection.write_u32::(frame.id())?; - connection.write(&frame.data())?; + connection.write_all(&frame.data())?; connection.flush().unwrap(); Ok(()) } diff --git a/candid_server/src/main.rs b/candid_server/src/main.rs index ae5711e..1dd3a19 100644 --- a/candid_server/src/main.rs +++ b/candid_server/src/main.rs @@ -73,11 +73,7 @@ fn main() { can_reader.add_client(tx); // Create client handler - clients.push(new_client_handler( - socket, - can_interface.clone().to_string(), - rx, - )); + clients.push(new_client_handler(socket, (*can_interface).to_string(), rx)); } } }