fix: 修复当读取到eof会丢掉本次读取消息的bug

main v0.5.2
NoahLan 2 years ago
parent 621db20ab1
commit 02775f087b

@ -8,6 +8,7 @@ import (
"git.noahlan.cn/noahlan/nnet/scheduler" "git.noahlan.cn/noahlan/nnet/scheduler"
"git.noahlan.cn/noahlan/ntools-go/core/nlog" "git.noahlan.cn/noahlan/ntools-go/core/nlog"
"git.noahlan.cn/noahlan/ntools-go/core/pool" "git.noahlan.cn/noahlan/ntools-go/core/pool"
"io"
"net" "net"
"sync/atomic" "sync/atomic"
) )
@ -199,12 +200,11 @@ func (r *connection) read() {
defer func() { defer func() {
_ = r.Close() _ = r.Close()
}() }()
buf := make([]byte, 4096) buf := make([]byte, 4096)
for { for {
n, err := r.conn.Read(buf) n, err := r.conn.Read(buf)
//nlog.Debugf("receive data %v", buf[:n]) //nlog.Debugf("receive data %v", buf[:n])
if err != nil { if err != nil && err != io.EOF {
nlog.Errorf("%s [readLoop] Read message error: %s, session will be closed immediately", nlog.Errorf("%s [readLoop] Read message error: %s, session will be closed immediately",
r.ngin.logPrefix(), err.Error()) r.ngin.logPrefix(), err.Error())
return return

Loading…
Cancel
Save