From 956b47f6ae4f4d70dff7643b75553e7974f48558 Mon Sep 17 00:00:00 2001 From: v2ray Date: Mon, 15 Aug 2016 14:31:46 +0200 Subject: [PATCH] release connection after all data read in freedom --- proxy/freedom/freedom.go | 43 ++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 3f30b8afa..f03fb4d18 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -2,7 +2,6 @@ package freedom import ( "io" - "sync" "github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app/dns" @@ -95,9 +94,6 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload * input := ray.OutboundInput() output := ray.OutboundOutput() - var readMutex, writeMutex sync.Mutex - readMutex.Lock() - writeMutex.Lock() if !payload.IsEmpty() { conn.Write(payload.Value) @@ -108,34 +104,25 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload * defer v2writer.Release() v2io.Pipe(input, v2writer) - writeMutex.Unlock() + if tcpConn, ok := conn.(*tcp.RawConnection); ok { + tcpConn.CloseWrite() + } }() - go func() { - defer readMutex.Unlock() + var reader io.Reader = conn - var reader io.Reader = conn - - timeout := this.timeout - if destination.IsUDP() { - timeout = 16 - } - if timeout > 0 { - reader = v2net.NewTimeOutReader(int(timeout) /* seconds */, conn) - } - - v2reader := v2io.NewAdaptiveReader(reader) - defer v2reader.Release() - - v2io.Pipe(v2reader, output) - ray.OutboundOutput().Close() - }() - - writeMutex.Lock() - if tcpConn, ok := conn.(*tcp.RawConnection); ok { - tcpConn.CloseWrite() + timeout := this.timeout + if destination.IsUDP() { + timeout = 16 } - readMutex.Lock() + if timeout > 0 { + reader = v2net.NewTimeOutReader(int(timeout) /* seconds */, conn) + } + + v2reader := v2io.NewAdaptiveReader(reader) + v2io.Pipe(v2reader, output) + v2reader.Release() + ray.OutboundOutput().Close() return nil }