1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-28 04:55:37 -05:00

Maintain an internal buffer pool to accelerate allocation

This commit is contained in:
V2Ray
2015-10-08 14:46:18 +02:00
parent 71df5103cd
commit 9ee73c4f6b
16 changed files with 241 additions and 122 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/binary"
"errors"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
)
@@ -15,7 +16,7 @@ var (
type Socks5UDPRequest struct {
Fragment byte
Address v2net.Address
Data []byte
Data *alloc.Buffer
}
func (request *Socks5UDPRequest) Destination() v2net.Destination {
@@ -40,7 +41,7 @@ func (request *Socks5UDPRequest) Bytes(buffer []byte) []byte {
buffer = append(buffer, []byte(request.Address.Domain())...)
}
buffer = append(buffer, request.Address.PortBytes()...)
buffer = append(buffer, request.Data...)
buffer = append(buffer, request.Data.Value...)
return buffer
}
@@ -74,8 +75,9 @@ func ReadUDPRequest(packet []byte) (request Socks5UDPRequest, err error) {
return
}
request.Data = make([]byte, len(packet)-dataBegin)
copy(request.Data, packet[dataBegin:])
request.Data = alloc.NewBuffer()
request.Data.Clear()
request.Data.Append(packet[dataBegin:])
return
}