mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
TcpService新增设置内存池接口
This commit is contained in:
@@ -15,6 +15,8 @@ type MsgParser struct {
|
||||
minMsgLen uint32
|
||||
maxMsgLen uint32
|
||||
littleEndian bool
|
||||
|
||||
INetMempool
|
||||
}
|
||||
|
||||
func NewMsgParser() *MsgParser {
|
||||
@@ -23,7 +25,7 @@ func NewMsgParser() *MsgParser {
|
||||
p.minMsgLen = 1
|
||||
p.maxMsgLen = 4096
|
||||
p.littleEndian = false
|
||||
|
||||
p.INetMempool = NewMemAreaPool()
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -99,9 +101,9 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
|
||||
|
||||
// data
|
||||
//msgData := make([]byte, msgLen)
|
||||
msgData := MakeByteSlice(int(msgLen))
|
||||
msgData := p.MakeByteSlice(int(msgLen))
|
||||
if _, err := io.ReadFull(conn, msgData); err != nil {
|
||||
ReleaseByteSlice(msgData)
|
||||
p.ReleaseByteSlice(msgData)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -124,7 +126,7 @@ func (p *MsgParser) Write(conn *TCPConn, args ...[]byte) error {
|
||||
}
|
||||
|
||||
//msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
|
||||
msg := MakeByteSlice(p.lenMsgLen+int(msgLen))
|
||||
msg := p.MakeByteSlice(p.lenMsgLen+int(msgLen))
|
||||
// write len
|
||||
switch p.lenMsgLen {
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user