in nmxact/nmble/ble_act.go [144:198]
func connCancel(x *BleXport, bl *Listener, r *BleConnCancelReq) error {
const rspType = MSG_TYPE_CONN_CANCEL
j, err := json.Marshal(r)
if err != nil {
return err
}
if err := x.Tx(j); err != nil {
return err
}
// Allow 10 seconds for the controller to cancel the connection.
rspTimeout := 10 * time.Second
rspTmoChan := time.After(rspTimeout)
bhdTmoChan := bl.AfterTimeout(x.RspTimeout())
for {
select {
case err := <-bl.ErrChan:
return err
case bm := <-bl.MsgChan:
switch msg := bm.(type) {
case *BleConnCancelRsp:
bl.Acked = true
switch msg.Status {
case 0:
// Cancel initiated. Await connect failure.
return nil
case ERR_CODE_EALREADY:
// No connect in progress. Pretend success.
return nil
default:
return StatusError(MSG_OP_RSP, rspType, msg.Status)
}
default:
}
case _, ok := <-bhdTmoChan:
if ok {
x.Restart("Blehostd timeout: " + MsgTypeToString(rspType))
}
bhdTmoChan = nil
case _, ok := <-rspTmoChan:
if ok {
x.Restart("Failed to cancel connect after " + rspTimeout.String())
}
rspTmoChan = nil
}
}
}