From c8c13e2787ac32177d2bddc610a77d374efb57eb Mon Sep 17 00:00:00 2001 From: AndyRN Date: Fri, 18 Oct 2024 16:53:49 +0100 Subject: [PATCH] Return clear error for connection timeout --- gap_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gap_linux.go b/gap_linux.go index 007da93..fa78424 100644 --- a/gap_linux.go +++ b/gap_linux.go @@ -363,9 +363,6 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err return Device{}, err } - if params.ConnectionTimeout <= 0 { - params.ConnectionTimeout = NewDuration(30 * time.Second) - } connectChan := make(chan error) go func() { for sig := range signal { @@ -392,12 +389,15 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err } }() go func() { + if params.ConnectionTimeout <= 0 { + params.ConnectionTimeout = NewDuration(30 * time.Second) + } time.Sleep(time.Duration(params.ConnectionTimeout)) connected, err := device.device.GetProperty("org.bluez.Device1.Connected") if !connected.Value().(bool) || err != nil { a.bus.RemoveSignal(signal) close(signal) - connectChan <- err + connectChan <- fmt.Errorf("connection timeout exceeded: %w", err) } }()