diff --git a/idevice/src/tcp/adapter.rs b/idevice/src/tcp/adapter.rs index 41d399b..c8d85f1 100644 --- a/idevice/src/tcp/adapter.rs +++ b/idevice/src/tcp/adapter.rs @@ -581,7 +581,7 @@ impl Adapter { } if res.flags.fin { ack_me = Some(res.destination_port); - state.status = ConnectionStatus::Error(ErrorKind::ConnectionReset); + state.status = ConnectionStatus::Error(ErrorKind::UnexpectedEof); } if res.flags.syn && res.flags.ack { ack_me = Some(res.destination_port); diff --git a/idevice/src/tcp/handle.rs b/idevice/src/tcp/handle.rs index 9ee240a..3434f9f 100644 --- a/idevice/src/tcp/handle.rs +++ b/idevice/src/tcp/handle.rs @@ -14,6 +14,8 @@ use tokio::{ sync::oneshot, }; +use crate::tcp::adapter::ConnectionStatus; + pub type ConnectToPortRes = oneshot::Sender, std::io::Error>>), std::io::Error>>; @@ -124,6 +126,23 @@ impl AdapterHandle { handles.remove(&hp); let _ = adapter.close(hp).await; } + + let mut to_close = Vec::new(); + for (&hp, tx) in &handles { + if let Ok(ConnectionStatus::Error(kind)) = adapter.get_status(hp) { + if kind == std::io::ErrorKind::UnexpectedEof { + to_close.push(hp); + } else { + let _ = tx.send(Err(std::io::Error::from(kind))); + to_close.push(hp); + } + } + } + for hp in to_close { + handles.remove(&hp); + // Best-effort close. For RST this just tidies state on our side + let _ = adapter.close(hp).await; + } } _ = tick.tick() => { diff --git a/idevice/src/tcp/mod.rs b/idevice/src/tcp/mod.rs index df755bd..c984672 100644 --- a/idevice/src/tcp/mod.rs +++ b/idevice/src/tcp/mod.rs @@ -5,7 +5,7 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -use log::debug; +use log::trace; use tokio::io::AsyncWriteExt; use crate::{ReadWrite, provider::RsdProvider}; @@ -16,7 +16,7 @@ pub mod packets; pub mod stream; pub(crate) fn log_packet(file: &Arc>, packet: &[u8]) { - debug!("Logging {} byte packet", packet.len()); + trace!("Logging {} byte packet", packet.len()); let packet = packet.to_vec(); let file = file.to_owned(); let now = SystemTime::now();