Repository: incubator-mynewt-newtmgr
Updated Branches:
  refs/heads/master 8c1863838 -> fc22b9fa5


nmxact - ble_xport - don't sync if bhd terminated


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/commit/fc22b9fa
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/tree/fc22b9fa
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/diff/fc22b9fa

Branch: refs/heads/master
Commit: fc22b9fa5d08b293499f37b4a098a43fa654fcb8
Parents: 8c18638
Author: Christopher Collins <[email protected]>
Authored: Wed May 10 18:10:17 2017 -0700
Committer: Christopher Collins <[email protected]>
Committed: Wed May 10 18:22:01 2017 -0700

----------------------------------------------------------------------
 nmxact/nmble/ble_fsm.go   |  8 +++++++-
 nmxact/nmble/ble_xport.go | 11 ++++++-----
 nmxact/nmxutil/nmxutil.go | 10 ----------
 3 files changed, 13 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/fc22b9fa/nmxact/nmble/ble_fsm.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_fsm.go b/nmxact/nmble/ble_fsm.go
index c79017e..828997a 100644
--- a/nmxact/nmble/ble_fsm.go
+++ b/nmxact/nmble/ble_fsm.go
@@ -85,6 +85,9 @@ type BleFsm struct {
        id         uint32
        wg         sync.WaitGroup
 
+       // Gets notified when the FSM has stopped due to an error.
+       errChan chan error
+
        // Protects all accesses to the FSM state variable.
        stateMtx sync.Mutex
 
@@ -280,6 +283,8 @@ func (bf *BleFsm) processErr(err error) {
 
        bf.errFunnel.Reset()
        bf.params.DisconnectCb(dt, peer, err)
+
+       bf.errChan <- err
 }
 
 func (bf *BleFsm) connectListen(seq BleSeq) error {
@@ -784,12 +789,13 @@ func (bf *BleFsm) startOnce() (bool, error) {
        }
 
        bf.errFunnel.Start()
+       bf.errChan = make(chan error, 1)
 
        for {
                retry, err := bf.executeState()
                if err != nil {
                        bf.errFunnel.Insert(err)
-                       bf.errFunnel.BlockUntilExp()
+                       err = <-bf.errChan
                        return retry, err
                } else if bf.getState() == SESN_STATE_DONE {
                        return false, nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/fc22b9fa/nmxact/nmble/ble_xport.go
----------------------------------------------------------------------
diff --git a/nmxact/nmble/ble_xport.go b/nmxact/nmble/ble_xport.go
index 091b607..0c2fe80 100644
--- a/nmxact/nmble/ble_xport.go
+++ b/nmxact/nmble/ble_xport.go
@@ -185,7 +185,9 @@ func (bx *BleXport) querySyncStatus() (bool, error) {
        }
        defer bx.Bd.RemoveListener(base)
 
-       bx.txNoSync(j)
+       if err := bx.txNoSync(j); err != nil {
+               return false, err
+       }
        for {
                select {
                case err := <-bl.ErrChan:
@@ -514,9 +516,9 @@ func (bx *BleXport) Start() error {
        return nil
 }
 
-func (bx *BleXport) txNoSync(data []byte) {
+func (bx *BleXport) txNoSync(data []byte) error {
        log.Debugf("Tx to blehostd:\n%s", hex.Dump(data))
-       bx.client.ToChild <- data
+       return bx.client.TxToChild(data)
 }
 
 func (bx *BleXport) Tx(data []byte) error {
@@ -524,8 +526,7 @@ func (bx *BleXport) Tx(data []byte) error {
                return err
        }
 
-       bx.txNoSync(data)
-       return nil
+       return bx.txNoSync(data)
 }
 
 func (bx *BleXport) RspTimeout() time.Duration {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/fc22b9fa/nmxact/nmxutil/nmxutil.go
----------------------------------------------------------------------
diff --git a/nmxact/nmxutil/nmxutil.go b/nmxact/nmxutil/nmxutil.go
index 75ce988..707b1bc 100644
--- a/nmxact/nmxutil/nmxutil.go
+++ b/nmxact/nmxutil/nmxutil.go
@@ -173,16 +173,6 @@ func (f *ErrFunnel) Reset() {
        }
 }
 
-func (f *ErrFunnel) BlockUntilExp() {
-       f.mtx.Lock()
-       defer f.mtx.Unlock()
-
-       if f.started {
-               f.resetMtx.Lock()
-               f.resetMtx.Unlock()
-       }
-}
-
 func (f *ErrFunnel) timerExp() {
        f.mtx.Lock()
        err := f.curErr

Reply via email to