diff options
Diffstat (limited to 'connector/external/external.go')
-rw-r--r-- | connector/external/external.go | 17 |
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) |