From f48504a2e48d72222e0a398d3fd76c72fc9e6ff0 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 23 Jan 2016 11:27:52 +0100 Subject: [PATCH] reuse buffer --- shell/point/inbound_detour_dynamic.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shell/point/inbound_detour_dynamic.go b/shell/point/inbound_detour_dynamic.go index 3b69720d5..0a628dc72 100644 --- a/shell/point/inbound_detour_dynamic.go +++ b/shell/point/inbound_detour_dynamic.go @@ -40,21 +40,26 @@ func (this *InboundDetourHandlerDynamic) refresh() error { this.Lock() defer this.Unlock() - this.ich2Recycle = this.ichInUse + this.ich2Recycle, this.ichInUse = this.ichInUse, this.ich2Recycle if this.ich2Recycle != nil { time.AfterFunc(time.Minute, func() { - for _, ich := range this.ich2Recycle { + for i := 0; i < len(this.ich2Recycle); i++ { + ich := this.ich2Recycle[i] if ich != nil { ich.handler.Close() delete(this.portsInUse, ich.port) } + this.ich2Recycle[i] = nil } }) } ichCount := this.config.Allocation.Concurrency // TODO: check ichCount - this.ichInUse = make([]*InboundConnectionHandlerWithPort, ichCount) + if this.ichInUse == nil { + this.ichInUse = make([]*InboundConnectionHandlerWithPort, ichCount) + } + for idx, _ := range this.ichInUse { port := this.pickUnusedPort() ich, err := proxyrepo.CreateInboundConnectionHandler(this.config.Protocol, this.space, this.config.Settings)