优化网络层

This commit is contained in:
boyce
2026-01-08 14:37:12 +08:00
parent 330644cebb
commit 2e4863d073
14 changed files with 94 additions and 60 deletions

View File

@@ -14,7 +14,8 @@ import (
type MsgParser struct {
LenMsgLen int
MinMsgLen uint32
MaxMsgLen uint32
MaxReadMsgLen uint32
MaxWriteMsgLen uint32
LittleEndian bool
bytespool.IBytesMemPool
@@ -67,7 +68,7 @@ func (p *MsgParser) Read(r io.Reader) ([]byte, error) {
}
// check len
if msgLen > p.MaxMsgLen {
if msgLen > p.MaxReadMsgLen {
return nil, errors.New("message too long")
} else if msgLen < p.MinMsgLen {
return nil, errors.New("message too short")
@@ -92,7 +93,7 @@ func (p *MsgParser) Write(conn io.Writer, args ...[]byte) error {
}
// check len
if msgLen > p.MaxMsgLen {
if p.MaxWriteMsgLen > 0 && msgLen > p.MaxWriteMsgLen {
return errors.New("message too long")
} else if msgLen < p.MinMsgLen {
return errors.New("message too short")