implement garbage collection of closed streams in streamsMap

ref #256
This commit is contained in:
Marten Seemann
2016-08-24 13:04:28 +07:00
committed by Lucas Clemente
parent 543ce21a5a
commit 15352e9591
2 changed files with 50 additions and 0 deletions

View File

@@ -180,3 +180,17 @@ func (m *streamsMap) NumberOfStreams() int {
m.mutex.RUnlock()
return n
}
// garbageCollectClosedStreams deletes nil values in the streams if they are smaller than protocol.MaxNewStreamIDDelta than the highest stream opened by the client
func (m *streamsMap) garbageCollectClosedStreams() {
m.mutex.Lock()
for id, str := range m.streams {
if str != nil {
continue
}
if id+protocol.MaxNewStreamIDDelta <= m.highestStreamOpenedByClient {
delete(m.streams, id)
}
}
m.mutex.Unlock()
}