优化增加TcpService的包长度字段配置

This commit is contained in:
duanhf2012
2023-03-22 14:59:22 +08:00
parent 95b153f8cf
commit 6b64de06a2
4 changed files with 51 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/binary"
"errors"
"io"
"math"
)
// --------------
@@ -19,18 +20,21 @@ type MsgParser struct {
}
func (p *MsgParser) getMaxMsgLen(lenMsgLen int) uint32 {
switch p.LenMsgLen {
case 1:
return math.MaxUint8
case 2:
return math.MaxUint16
case 4:
return math.MaxUint32
default:
panic("LenMsgLen value must be 1 or 2 or 4")
}
}
func (p *MsgParser) init(){
p.INetMempool = NewMemAreaPool()
for i:=1;i<=4;i*=2 {
max := uint32(1<<(i*8)-1)
if p.MaxMsgLen <= max {
p.LenMsgLen = i
return
}
}
panic("MaxMsgLen value must be less than 4294967295")
}
// goroutine safe