only set a read deadline when the keep-alive value is positive (#83)

This commit is contained in:
gerdstolpmann authored and GitHub committed 2020-04-16 10:33:17 +08:00
1 parent af7db83bdc
commit a1bf3d93b2
1 file changed
+9 -7
+9 -7
View File
@@ -121,14 +121,16 @@ func (c *client) readLoop() {
return
default:
//add read timeout
if err := nc.SetReadDeadline(time.Now().Add(timeOut)); err != nil {
log.Error("set read timeout error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
msg := &Message{
client: c,
packet: DisconnectdPacket,
if keepAlive > 0 {
if err := nc.SetReadDeadline(time.Now().Add(timeOut)); err != nil {
log.Error("set read timeout error: ", zap.Error(err), zap.String("ClientID", c.info.clientID))
msg := &Message{
client: c,
packet: DisconnectdPacket,
}
b.SubmitWork(c.info.clientID, msg)
return
}
b.SubmitWork(c.info.clientID, msg)
return
}
packet, err := packets.ReadPacket(nc)