mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 23:06:30 -05:00
releasable writer
This commit is contained in:
parent
760247a4ab
commit
e8023f0d92
@ -3,6 +3,7 @@ package io
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
)
|
||||
|
||||
@ -12,6 +13,11 @@ type Writer interface {
|
||||
Write(*alloc.Buffer) error
|
||||
}
|
||||
|
||||
type ReleasableWriter interface {
|
||||
Writer
|
||||
common.Releasable
|
||||
}
|
||||
|
||||
// AdaptiveWriter is a Writer that writes alloc.Buffer into underlying writer.
|
||||
type AdaptiveWriter struct {
|
||||
writer io.Writer
|
||||
|
@ -179,11 +179,12 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.TCPConn) {
|
||||
|
||||
writer.SetCached(false)
|
||||
go func(finish *sync.Mutex) {
|
||||
var writer v2io.Writer = v2io.NewAdaptiveWriter(bodyWriter)
|
||||
var writer v2io.ReleasableWriter = v2io.NewAdaptiveWriter(bodyWriter)
|
||||
if request.Option.IsChunkStream() {
|
||||
writer = vmessio.NewAuthChunkWriter(writer)
|
||||
}
|
||||
v2io.ChanToWriter(writer, output)
|
||||
writer.Release()
|
||||
finish.Unlock()
|
||||
}(&writeFinish)
|
||||
writeFinish.Lock()
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
)
|
||||
|
||||
type AuthChunkWriter struct {
|
||||
writer v2io.Writer
|
||||
writer v2io.ReleasableWriter
|
||||
}
|
||||
|
||||
func NewAuthChunkWriter(writer v2io.Writer) *AuthChunkWriter {
|
||||
func NewAuthChunkWriter(writer v2io.ReleasableWriter) *AuthChunkWriter {
|
||||
return &AuthChunkWriter{
|
||||
writer: writer,
|
||||
}
|
||||
@ -24,6 +24,7 @@ func (this *AuthChunkWriter) Write(buffer *alloc.Buffer) error {
|
||||
}
|
||||
|
||||
func (this *AuthChunkWriter) Release() {
|
||||
this.writer.Release()
|
||||
this.writer = nil
|
||||
}
|
||||
|
||||
|
@ -116,11 +116,12 @@ func (this *VMessOutboundHandler) handleRequest(session *raw.ClientSession, conn
|
||||
writer.SetCached(false)
|
||||
|
||||
if moreChunks {
|
||||
var streamWriter v2io.Writer = v2io.NewAdaptiveWriter(bodyWriter)
|
||||
var streamWriter v2io.ReleasableWriter = v2io.NewAdaptiveWriter(bodyWriter)
|
||||
if request.Option.IsChunkStream() {
|
||||
streamWriter = vmessio.NewAuthChunkWriter(streamWriter)
|
||||
}
|
||||
v2io.ChanToWriter(streamWriter, input)
|
||||
streamWriter.Release()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user