Skip to content

Commit

Permalink
gattc/linux: DiscoverServices times out in 10s
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored and deadprogram committed Nov 5, 2021
1 parent 7f3b96c commit bd75a42
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gattc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (s *DeviceService) UUID() UUID {
// On Linux with BlueZ, this just waits for the ServicesResolved signal (if
// services haven't been resolved yet) and uses this list of cached services.
func (d *Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
start := time.Now()

for {
resolved, err := d.device.GetServicesResolved()
if err != nil {
Expand All @@ -48,6 +50,9 @@ func (d *Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
}
// This is a terrible hack, but I couldn't find another way.
time.Sleep(10 * time.Millisecond)
if time.Since(start) > 10*time.Second {
return nil, errors.New("timeout on DiscoverServices")
}
}

services := []DeviceService{}
Expand Down

0 comments on commit bd75a42

Please sign in to comment.