mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化增加TcpService的包长度字段配置
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user