added ErrorEventChan

master v1.4.0
cheetah.cat 3 months ago
parent accc7639e4
commit 733dc9665e

@ -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
}
}
}

Loading…
Cancel
Save