优化payload

This commit is contained in:
bjdgyc
2021-07-29 19:02:55 +08:00
parent 3937d1eb65
commit 583ca4d635
5 changed files with 69 additions and 72 deletions

View File

@@ -3,14 +3,21 @@ package handler
import (
"sync"
"github.com/bjdgyc/anylink/base"
"github.com/bjdgyc/anylink/sessdata"
)
var plPool = sync.Pool{
// 不允许直接修改
// [6] => PType
var plHeader = []byte{'S', 'T', 'F', 0x01, 0x00, 0x00, 0x00, 0x00}
var plPool = &sync.Pool{
New: func() interface{} {
b := make([]byte, 0, BufferSize)
b := make([]byte, BufferSize)
pl := sessdata.Payload{
Data: &b,
LType: sessdata.LTypeIPData,
PType: 0x00,
Data: &b,
}
// fmt.Println("plPool-init", len(pl.Data), cap(pl.Data))
return &pl
@@ -23,13 +30,19 @@ func getPayload() *sessdata.Payload {
}
func putPayload(pl *sessdata.Payload) {
pl.LType = 0
pl.PType = 0
*pl.Data = (*pl.Data)[:0]
// 错误数据丢弃
if cap(*pl.Data) != BufferSize {
base.Warn("payload cap is err", cap(*pl.Data))
return
}
pl.LType = sessdata.LTypeIPData
pl.PType = 0x00
*pl.Data = (*pl.Data)[:BufferSize]
plPool.Put(pl)
}
var bytePool = sync.Pool{
var bytePool = &sync.Pool{
New: func() interface{} {
b := make([]byte, 0, BufferSize)
// fmt.Println("bytePool-init")