1
0
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:
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 (
"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)

View File

@@ -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)
}()