mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-05 16:55:27 -05:00
Maintain an internal buffer pool to accelerate allocation
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
|
||||
"github.com/v2ray/v2ray-core"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@@ -25,7 +26,10 @@ func (handler *InboundConnectionHandler) Communicate(packet v2net.Packet) error
|
||||
input := ray.InboundInput()
|
||||
output := ray.InboundOutput()
|
||||
|
||||
input <- handler.Data2Send
|
||||
buffer := alloc.NewBuffer()
|
||||
buffer.Clear()
|
||||
buffer.Append(handler.Data2Send)
|
||||
input <- buffer
|
||||
close(input)
|
||||
|
||||
v2net.ChanToWriter(handler.DataReturned, output)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
|
||||
"github.com/v2ray/v2ray-core"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@@ -19,7 +20,7 @@ func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray core
|
||||
|
||||
handler.Destination = packet.Destination()
|
||||
if packet.Chunk() != nil {
|
||||
handler.Data2Send.Write(packet.Chunk())
|
||||
handler.Data2Send.Write(packet.Chunk().Value)
|
||||
}
|
||||
|
||||
go func() {
|
||||
@@ -28,11 +29,13 @@ func (handler *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray core
|
||||
if !open {
|
||||
break
|
||||
}
|
||||
handler.Data2Send.Write(data)
|
||||
handler.Data2Send.Write(data.Value)
|
||||
data.Release()
|
||||
}
|
||||
dataCopy := make([]byte, len(handler.Data2Return))
|
||||
copy(dataCopy, handler.Data2Return)
|
||||
output <- dataCopy
|
||||
response := alloc.NewBuffer()
|
||||
response.Clear()
|
||||
response.Append(handler.Data2Return)
|
||||
output <- response
|
||||
close(output)
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user