From 733dc9665ea7b72f57ec5ae76b175718ba50c80d Mon Sep 17 00:00:00 2001 From: "cheetah.cat" Date: Tue, 17 Sep 2024 01:39:27 +0200 Subject: [PATCH] added ErrorEventChan --- client/client.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 0e66271..eb93c7f 100644 --- a/client/client.go +++ b/client/client.go @@ -33,6 +33,7 @@ type ZelloClient struct { // Event Chans GeneralEventChan chan ZelloResponsePacked BinaryDataChan chan []byte + ErrorEventChan chan error } func NewZelloClient() (zelloClient *ZelloClient) { @@ -43,6 +44,7 @@ func NewZelloClient() (zelloClient *ZelloClient) { DefaultTimeout: time.Millisecond * 1e3, SeqResponseChans: make(map[int64]chan map[string]interface{}), GeneralEventChan: make(chan ZelloResponsePacked), + ErrorEventChan: make(chan error), BinaryDataChan: make(chan []byte), } } @@ -484,25 +486,26 @@ func (zc *ZelloClient) handleRXbinary(data []byte) (err error) { return nil } -func (zc *ZelloClient) Work() { +func (zc *ZelloClient) Work() (err error) { for { msgType, message, err := zc.Connection.ReadMessage() if err != nil { - log.Println("read:", err) - return + //log.Println("read:", err) + zc.ErrorEventChan <- err + return err } if msgType == websocket.TextMessage { err = zc.handleRXjson(message) if err != nil { log.Println("handleRXjson:", err) - return + return err } } if msgType == websocket.BinaryMessage { err = zc.handleRXbinary(message) if err != nil { log.Println("handleRXbinary:", err) - return + return err } } }