From e94414c4febb393b50dd5e1dd6013d527f6eb293 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 29 Mar 2026 17:22:31 -0700 Subject: [PATCH] fix(linux-rust): Retry L2CAP send on ENOTCONN during BlueZ Handshake This fix allows the send thread to make 10 attempts to send it's data. This gives access to seeing the battery status --- linux-rust/src/bluetooth/aacp.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/linux-rust/src/bluetooth/aacp.rs b/linux-rust/src/bluetooth/aacp.rs index a2b6d491f..0e18a3343 100644 --- a/linux-rust/src/bluetooth/aacp.rs +++ b/linux-rust/src/bluetooth/aacp.rs @@ -1191,11 +1191,23 @@ async fn recv_thread(manager: AACPManager, sp: Arc) { async fn send_thread(mut rx: mpsc::Receiver>, sp: Arc) { while let Some(data) = rx.recv().await { - if let Err(e) = sp.send(&data).await { - error!("Failed to send data: {}", e); - break; + let mut attempts = 0; + loop { + match sp.send(&data).await { + Ok(_) => { + debug!("Sent {} bytes: {}", data.len(), hex::encode(&data)); + break; + } + Err(e) if e.raw_os_error() == Some(107) && attempts < 10 => { + attempts += 1; + sleep(Duration::from_millis(100)).await; + } + Err(e) => { + error!("Failed to send data: {}", e); + return; + } + } } - debug!("Sent {} bytes: {}", data.len(), hex::encode(&data)); } info!("Send thread finished."); }