mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
修改网络内存池接口
This commit is contained in:
@@ -62,7 +62,7 @@ func (areaPool *memAreaPool) releaseByteSlice(byteBuff []byte) bool{
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeByteSlice(size int) []byte{
|
func MakeByteSlice(size int) []byte{
|
||||||
for i:=0;i<len(memAreaPoolList);i++{
|
for i:=0;i<len(memAreaPoolList);i++{
|
||||||
if size <= memAreaPoolList[i].maxAreaValue {
|
if size <= memAreaPoolList[i].maxAreaValue {
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func (p *MsgParser) Read(conn *TCPConn) ([]byte, error) {
|
|||||||
|
|
||||||
// data
|
// data
|
||||||
//msgData := make([]byte, msgLen)
|
//msgData := make([]byte, msgLen)
|
||||||
msgData := makeByteSlice(int(msgLen))
|
msgData := MakeByteSlice(int(msgLen))
|
||||||
if _, err := io.ReadFull(conn, msgData); err != nil {
|
if _, err := io.ReadFull(conn, msgData); err != nil {
|
||||||
ReleaseByteSlice(msgData)
|
ReleaseByteSlice(msgData)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -124,7 +124,7 @@ func (p *MsgParser) Write(conn *TCPConn, args ...[]byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
|
//msg := make([]byte, uint32(p.lenMsgLen)+msgLen)
|
||||||
msg := makeByteSlice(p.lenMsgLen+int(msgLen))
|
msg := MakeByteSlice(p.lenMsgLen+int(msgLen))
|
||||||
// write len
|
// write len
|
||||||
switch p.lenMsgLen {
|
switch p.lenMsgLen {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user