From cb9783ec68f453cf39c093336a5c81c8177e5976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C4=ABls?= Date: Fri, 13 Dec 2024 15:48:08 +0100 Subject: [PATCH] fixup! Use IAN TCP connection for ephemeral peer exchange Fix clippy lints --- .../ios_tcp_connection.rs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/mullvad-ios/src/ephemeral_peer_proxy/ios_tcp_connection.rs b/mullvad-ios/src/ephemeral_peer_proxy/ios_tcp_connection.rs index 903733fadefa..29d05bd506a6 100644 --- a/mullvad-ios/src/ephemeral_peer_proxy/ios_tcp_connection.rs +++ b/mullvad-ios/src/ephemeral_peer_proxy/ios_tcp_connection.rs @@ -92,12 +92,14 @@ pub struct IosTcpProvider { funcs: WgTcpConnectionFuncs, } +type InFlightIoTask = Option>>>>>; + pub struct IosTcpConnection { tunnel_handle: i32, socket_handle: i32, funcs: WgTcpConnectionFuncs, - in_flight_read: Option>>>>>, - in_flight_write: Option>>>>>, + in_flight_read: InFlightIoTask, + in_flight_write: InFlightIoTask, } #[derive(Debug)] @@ -244,17 +246,20 @@ impl AsyncRead for IosTcpConnection { // `funcs.receive_fn` must be a valid function pointer. let result = unsafe { funcs.receive(tunnel_handle, socket_handle, buffer.as_mut_slice()) }; - if result < 0 { - Err(io::Error::new( + match result { + size @ 1.. => { + buffer.truncate(size as usize); + Ok(buffer) + } + + errval @ ..0 => Err(io::Error::new( io::ErrorKind::Other, - format!("Read error: {}", result), - )) - } else if result == 0 { - Err(connection_closed_err()) - } else { - buffer.truncate(result as usize); - Ok(buffer) + format!("Read error: {}", errval), + )), + + 0 => Err(connection_closed_err()), } + }); self.in_flight_read = Some(Box::pin(task));