[bt][tools] Fix bug in bt-le-central connection
Fixed regression caused by the FIDL event stream handler function
which didn't propagate the future returned by one of the match cases.
This caused the connect_peripheral future to not be polled and drop
its gatt.Client handle.
Test: "bt-le-central scan -c" connects, lists GATT services, and starts
the GATT REPL.
Change-Id: I49893aea74fe68b5783574bae3d577e120a18463
diff --git a/bin/bluetooth/tools/bt-le-central/src/common/central.rs b/bin/bluetooth/tools/bt-le-central/src/common/central.rs
index aefea43..b7a97d7 100644
--- a/bin/bluetooth/tools/bt-le-central/src/common/central.rs
+++ b/bin/bluetooth/tools/bt-le-central/src/common/central.rs
@@ -55,33 +55,44 @@
match evt {
CentralEvent::OnScanStateChanged { scanning } => {
eprintln!(" scan state changed: {}", scanning);
+ Left(future::ok(()))
}
CentralEvent::OnDeviceDiscovered { device } => {
let id = device.identifier.clone();
let connectable = device.connectable;
+
eprintln!(" {}", RemoteDeviceWrapper(device));
+
let central = state.read();
- if central.scan_once || central.connect {
- // Stop scanning.
- if let Err(e) = central.svc.stop_scan() {
- eprintln!("request to stop scan failed: {}", e);
+ if !central.scan_once && !central.connect {
+ return Left(future::ok(()));
+ }
+
+ // Stop scanning.
+ if let Err(e) = central.svc.stop_scan() {
+ eprintln!("request to stop scan failed: {}", e);
+ // TODO(armansito): kill the channel here instead
+ exit(0);
+ Left(future::ok(()))
+ } else if central.connect && connectable {
+ Right(connect_peripheral(state.clone(), id).recover(|_| {
// TODO(armansito): kill the channel here instead
exit(0);
- } else if central.connect && connectable {
- connect_peripheral(state.clone(), id);
- } else {
- // TODO(armansito): kill the channel here instead
- exit(0);
- }
+ ()
+ }))
+ } else {
+ // TODO(armansito): kill the channel here instead
+ exit(0);
+ Left(future::ok(()))
}
}
CentralEvent::OnPeripheralDisconnected { identifier } => {
eprintln!(" peer disconnected: {}", identifier);
// TODO(armansito): Close the channel here instead
exit(0);
+ Left(future::ok(()))
}
}
- future::ok(())
})
.map(|_| ())
.recover(|e| eprintln!("failed to subscribe to BLE Central events: {:?}", e))
@@ -107,7 +118,7 @@
.svc
.connect_peripheral(&mut id, server)
.map_err(|e| {
- BTError::new(&format!("failed to initiaate connect request: {}", e)).into()
+ BTError::new(&format!("failed to initiate connect request: {}", e)).into()
})
.and_then(move |status| match status.error {
Some(e) => {