aboutsummaryrefslogtreecommitdiff
path: root/connector/external
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-03-01 13:27:29 +0100
committerAlex Auvolat <alex@adnab.me>2020-03-01 13:27:29 +0100
commit018f4a751ac4bff9113874666a92b4c5d8679af3 (patch)
tree41670a7c39287344562d2992146cd9c3d6bc94f8 /connector/external
parent810e75a34dddd88279bea1cd2ea38816fe872d52 (diff)
downloadeasybridge-018f4a751ac4bff9113874666a92b4c5d8679af3.tar.gz
easybridge-018f4a751ac4bff9113874666a92b4c5d8679af3.zip
Read backlog; handle messages in the correct order
Diffstat (limited to 'connector/external')
-rw-r--r--connector/external/external.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/connector/external/external.go b/connector/external/external.go
index 741802c..9a4137d 100644
--- a/connector/external/external.go
+++ b/connector/external/external.go
@@ -86,6 +86,7 @@ type External struct {
generation int
proc *exec.Cmd
+ handlerChan chan *extMessageWithData
counter uint64
inflightRequests map[uint64]chan *extMessageWithData
lock sync.Mutex
@@ -110,6 +111,9 @@ func (ext *External) Configure(c Configuration) error {
ext.generation += 1
+ ext.handlerChan = make(chan *extMessageWithData)
+ go ext.handlerLoop(ext.generation)
+
err = ext.setupProc()
if err != nil {
return err
@@ -254,7 +258,17 @@ func (ext *External) recvLoop() {
}
}()
} else {
- go ext.handleCmd(&msg)
+ ext.handlerChan <- &msg
+ }
+ }
+}
+
+func (ext *External) handlerLoop(generation int) {
+ for ext.handlerChan != nil && ext.generation == generation {
+ select {
+ case msg := <-ext.handlerChan:
+ ext.handleCmd(msg)
+ case <-time.After(10 * time.Second):
}
}
}
@@ -311,6 +325,7 @@ func (ext *External) Close() {
ext.recv = nil
ext.send = nil
ext.sendJson = nil
+ ext.handlerChan = nil
go func() {
time.Sleep(10 * time.Second)