mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 04:17:38 +03:00
35 lines
625 B
Go
35 lines
625 B
Go
package network
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/sagernet/sing/common/buf"
|
|
M "github.com/sagernet/sing/common/metadata"
|
|
)
|
|
|
|
type PacketBuffer struct {
|
|
Buffer *buf.Buffer
|
|
Destination M.Socksaddr
|
|
}
|
|
|
|
var packetPool = sync.Pool{
|
|
New: func() any {
|
|
return new(PacketBuffer)
|
|
},
|
|
}
|
|
|
|
func NewPacketBuffer() *PacketBuffer {
|
|
return packetPool.Get().(*PacketBuffer)
|
|
}
|
|
|
|
func PutPacketBuffer(packet *PacketBuffer) {
|
|
*packet = PacketBuffer{}
|
|
packetPool.Put(packet)
|
|
}
|
|
|
|
func ReleaseMultiPacketBuffer(packetBuffers []*PacketBuffer) {
|
|
for _, packet := range packetBuffers {
|
|
packet.Buffer.Release()
|
|
PutPacketBuffer(packet)
|
|
}
|
|
}
|