reuse buffer

pull/73/head
v2ray 2016-01-23 11:27:52 +01:00
parent 19b8b54672
commit f48504a2e4
1 changed files with 8 additions and 3 deletions

View File

@ -40,21 +40,26 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
this.Lock() this.Lock()
defer this.Unlock() defer this.Unlock()
this.ich2Recycle = this.ichInUse this.ich2Recycle, this.ichInUse = this.ichInUse, this.ich2Recycle
if this.ich2Recycle != nil { if this.ich2Recycle != nil {
time.AfterFunc(time.Minute, func() { 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 { if ich != nil {
ich.handler.Close() ich.handler.Close()
delete(this.portsInUse, ich.port) delete(this.portsInUse, ich.port)
} }
this.ich2Recycle[i] = nil
} }
}) })
} }
ichCount := this.config.Allocation.Concurrency ichCount := this.config.Allocation.Concurrency
// TODO: check ichCount // TODO: check ichCount
this.ichInUse = make([]*InboundConnectionHandlerWithPort, ichCount) if this.ichInUse == nil {
this.ichInUse = make([]*InboundConnectionHandlerWithPort, ichCount)
}
for idx, _ := range this.ichInUse { for idx, _ := range this.ichInUse {
port := this.pickUnusedPort() port := this.pickUnusedPort()
ich, err := proxyrepo.CreateInboundConnectionHandler(this.config.Protocol, this.space, this.config.Settings) ich, err := proxyrepo.CreateInboundConnectionHandler(this.config.Protocol, this.space, this.config.Settings)