From 06d75da257d7960b906893e498eda53484559d61 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Sat, 11 Jun 2022 20:38:16 +0800 Subject: [PATCH] Chore: adjust Relay copy memory alloc logic --- common/net/relay.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/common/net/relay.go b/common/net/relay.go index e7157639..99a0c6ad 100644 --- a/common/net/relay.go +++ b/common/net/relay.go @@ -4,8 +4,6 @@ import ( "io" "net" "time" - - "github.com/Dreamacro/clash/common/pool" ) // Relay copies between left and right bidirectionally. @@ -13,18 +11,14 @@ func Relay(leftConn, rightConn net.Conn) { ch := make(chan error) go func() { - buf := pool.Get(pool.RelayBufferSize) // Wrapping to avoid using *net.TCPConn.(ReadFrom) // See also https://github.com/Dreamacro/clash/pull/1209 - _, err := io.CopyBuffer(WriteOnlyWriter{Writer: leftConn}, ReadOnlyReader{Reader: rightConn}, buf) - pool.Put(buf) + _, err := io.Copy(WriteOnlyWriter{Writer: leftConn}, ReadOnlyReader{Reader: rightConn}) leftConn.SetReadDeadline(time.Now()) ch <- err }() - buf := pool.Get(pool.RelayBufferSize) - io.CopyBuffer(WriteOnlyWriter{Writer: rightConn}, ReadOnlyReader{Reader: leftConn}, buf) - pool.Put(buf) + io.Copy(WriteOnlyWriter{Writer: rightConn}, ReadOnlyReader{Reader: leftConn}) rightConn.SetReadDeadline(time.Now()) <-ch }