Skip to content

Commit 3b8fa97

Browse files
committed
added a read timeout in the enumerate method to stop hangs when scanning
devices
1 parent 45ac363 commit 3b8fa97

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ This only affects `--listen`. All other operations (read, write, discovery) work
367367

368368
### Enumerate Device (Table View)
369369

370-
Inspired by [bleah](https://github.com/hackgnar/bleah)'s `-e` flag, `--enumerate` connects to a device and displays a full overview of all services, characteristics, descriptors, and readable values in a color-coded table view using the [Catppuccin Mocha](https://github.com/catppuccin/catppuccin) color palette.
370+
Inspired by bleah and bettercap, `--enumerate` connects to a device and displays a full overview of all services, characteristics, descriptors, and readable values in a color-coded table view using the [Catppuccin Mocha](https://github.com/catppuccin/catppuccin) color palette.
371371

372372
```bash
373373
gratttool -b AA:BB:CC:DD:EE:FF --enumerate

src/gatt.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use bluer::gatt::WriteOp;
99
use futures::StreamExt;
1010
use std::io::Write;
1111
use std::pin::Pin;
12+
use std::time::Duration;
1213

1314
/// Discover all primary services, printing in gatttool non-interactive format
1415
pub async fn discover_primary(
@@ -410,9 +411,14 @@ pub async fn enumerate(conn: &Connection) -> Result<(), GrattError> {
410411
let data = if (properties.0 & CharProps::READ) != 0
411412
&& (properties.0 & CharProps::INDICATE) == 0
412413
{
413-
match characteristic.read().await {
414-
Ok(d) => Some(d),
415-
Err(_) => None,
414+
match tokio::time::timeout(
415+
Duration::from_secs(3),
416+
characteristic.read(),
417+
)
418+
.await
419+
{
420+
Ok(Ok(d)) => Some(d),
421+
_ => None,
416422
}
417423
} else {
418424
None

0 commit comments

Comments
 (0)