From 150bf7fc65c7736d7c56e2ce7866f03a620d9014 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 20 Oct 2023 08:39:04 +0800 Subject: [PATCH] chore: decrease memory copy in sing listener --- listener/sing/sing.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/listener/sing/sing.go b/listener/sing/sing.go index 1837951d..ff72f67d 100644 --- a/listener/sing/sing.go +++ b/listener/sing/sing.go @@ -193,12 +193,6 @@ func (c *packet) WriteBack(b []byte, addr net.Addr) (n int, err error) { err = errors.New("address is invalid") return } - buff := buf.NewPacket() - defer buff.Release() - n, err = buff.Write(b) - if err != nil { - return - } c.mutex.Lock() defer c.mutex.Unlock() @@ -207,6 +201,14 @@ func (c *packet) WriteBack(b []byte, addr net.Addr) (n int, err error) { err = errors.New("writeBack to closed connection") return } + + buff := buf.NewPacket() + defer buff.Release() + n, err = buff.Write(b) + if err != nil { + return + } + err = conn.WritePacket(buff, M.SocksaddrFromNet(addr)) if err != nil { return