Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux

go:
- 1.7
- 1.8
- 1.9
- tip
Expand Down
33 changes: 20 additions & 13 deletions linux/hci/gap.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,35 @@ func (h *HCI) Dial(ctx context.Context, a ble.Addr) (ble.Client, error) {
if h.dialerTmo != time.Duration(0) {
tmo = time.After(h.dialerTmo)
}

select {
case <-ctx.Done():
return nil, ctx.Err()
return h.cancelDial()
case <-tmo:
return h.cancelDial()
case <-h.done:
return nil, h.err
case c := <-h.chMasterConn:
return gatt.NewClient(c)
case <-tmo:
err := h.Send(&h.params.connCancel, nil)
if err == nil {
// The pending connection was canceled successfully.
return nil, fmt.Errorf("connection timed out")
}
// The connection has been established, the cancel command
// failed with ErrDisallowed.
if err == ErrDisallowed {
return gatt.NewClient(<-h.chMasterConn)
}
return nil, errors.Wrap(err, "cancel connection failed")

}
}

// cancelDial cancels the Dialing
func (h *HCI) cancelDial() (ble.Client, error) {
err := h.Send(&h.params.connCancel, nil)
if err == nil {
// The pending connection was canceled successfully.
return nil, fmt.Errorf("connection canceled")
}
// The connection has been established, the cancel command
// failed with ErrDisallowed.
if err == ErrDisallowed {
return gatt.NewClient(<-h.chMasterConn)
}
return nil, errors.Wrap(err, "cancel connection failed")
}

// Advertise starts advertising.
func (h *HCI) Advertise() error {
h.params.advEnable.AdvertisingEnable = 1
Expand Down