not show log by default

This commit is contained in:
2022-02-23 14:36:12 +08:00
parent bd262df8ea
commit f51d2c7137
4 changed files with 35 additions and 4 deletions
+17 -2
View File
@@ -42,6 +42,7 @@ type ClientCommon struct {
heartbeatPeriod time.Duration
wg stario.WaitGroup
netType NetType
showError bool
skipKeyExchange bool
useHeartBeat bool
sequenceDe func([]byte) (interface{}, error)
@@ -201,6 +202,12 @@ func (c *ClientCommon) Heartbeat() {
}
}
func (c *ClientCommon) ShowError(std bool) {
c.mu.Lock()
c.showError = std
c.mu.Unlock()
}
func (c *ClientCommon) readMessage() {
for {
select {
@@ -221,7 +228,9 @@ func (c *ClientCommon) readMessage() {
continue
}
if err != nil {
fmt.Println("client read error", err)
if c.showError {
fmt.Println("client read error", err)
}
c.alive.Store(false)
c.mu.Lock()
c.status = Status{
@@ -269,7 +278,9 @@ func (c *ClientCommon) loadMessage() {
//transfer to Msg
msg, err := c.sequenceDe(c.msgDe(c.SecretKey, data.Msg))
if err != nil {
fmt.Println("client decode data error", err)
if c.showError {
fmt.Println("client decode data error", err)
}
return
}
message := Message{
@@ -399,6 +410,8 @@ func (c *ClientCommon) sendWait(msg TransferMsg, timeout time.Duration) (Message
close(data.Reply)
c.noFinSyncMsgPool.Delete(data.TransferMsg.ID)
return Message{}, os.ErrDeadlineExceeded
case <-c.stopCtx.Done():
return Message{}, errors.New("Service shutdown")
case msg, ok := <-data.Reply:
if !ok {
return msg, os.ErrInvalid
@@ -420,6 +433,8 @@ func (c *ClientCommon) sendCtx(msg TransferMsg, ctx context.Context) (Message, e
close(data.Reply)
c.noFinSyncMsgPool.Delete(data.TransferMsg.ID)
return Message{}, os.ErrDeadlineExceeded
case <-c.stopCtx.Done():
return Message{}, errors.New("Service shutdown")
case msg, ok := <-data.Reply:
if !ok {
return msg, os.ErrInvalid