Skip to content

Commit a78a8bb

Browse files
authored
fix(linux-rust): Retry L2CAP send on ENOTCONN during BlueZ Handshake (#495)
This fix allows the send thread to make 10 attempts to send it's data. This gives access to seeing the battery status
1 parent 2f1208c commit a78a8bb

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

linux-rust/src/bluetooth/aacp.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,23 @@ async fn recv_thread(manager: AACPManager, sp: Arc<SeqPacket>) {
12331233

12341234
async fn send_thread(mut rx: mpsc::Receiver<Vec<u8>>, sp: Arc<SeqPacket>) {
12351235
while let Some(data) = rx.recv().await {
1236-
if let Err(e) = sp.send(&data).await {
1237-
error!("Failed to send data: {}", e);
1238-
break;
1236+
let mut attempts = 0;
1237+
loop {
1238+
match sp.send(&data).await {
1239+
Ok(_) => {
1240+
debug!("Sent {} bytes: {}", data.len(), hex::encode(&data));
1241+
break;
1242+
}
1243+
Err(e) if e.raw_os_error() == Some(107) && attempts < 10 => {
1244+
attempts += 1;
1245+
sleep(Duration::from_millis(100)).await;
1246+
}
1247+
Err(e) => {
1248+
error!("Failed to send data: {}", e);
1249+
return;
1250+
}
1251+
}
12391252
}
1240-
debug!("Sent {} bytes: {}", data.len(), hex::encode(&data));
12411253
}
12421254
info!("Send thread finished.");
12431255
}

0 commit comments

Comments
 (0)