Unverified Commit 0dba3c0c authored by Eric Stutzenberger's avatar Eric Stutzenberger Committed by GitHub
Browse files

Merge pull request #3 from rigado/fix/init_error

Clean up if device intialization fails.
parents 3b8c738f b3fe2e92
......@@ -28,17 +28,20 @@ func NewDeviceWithNameAndHandler(name string, handler ble.NotifyHandler, opts ..
return nil, errors.Wrap(err, "can't create hci")
}
if err = dev.Init(); err != nil {
dev.Close()
return nil, errors.Wrap(err, "can't init hci")
}
srv, err := gatt.NewServerWithNameAndHandler(name, handler)
if err != nil {
dev.Close()
return nil, errors.Wrap(err, "can't create server")
}
// mtu := ble.DefaultMTU
mtu := ble.MaxMTU // TODO: get this from user using Option.
if mtu > ble.MaxMTU {
dev.Close()
return nil, errors.Wrapf(err, "maximum ATT_MTU is %d", ble.MaxMTU)
}
......
......@@ -293,7 +293,10 @@ func (h *HCI) sktLoop() {
func (h *HCI) close(err error) error {
h.err = err
return h.skt.Close()
if h.skt != nil {
return h.skt.Close()
}
return err
}
func (h *HCI) handlePkt(b []byte) error {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment