only iterate over open Streams in StreamsMap

ref #256
This commit is contained in:
Marten Seemann
2016-08-06 14:41:47 +07:00
parent b0d116ad5a
commit 1a30313ace
2 changed files with 11 additions and 11 deletions

View File

@@ -44,7 +44,14 @@ func (m *streamsMap) Iterate(fn streamLambda) error {
m.mutex.Lock()
defer m.mutex.Unlock()
for _, str := range m.streams {
for _, streamID := range m.openStreams {
str, ok := m.streams[streamID]
if !ok {
return errMapAccess
}
if str == nil {
return fmt.Errorf("BUG: Stream %d is closed, but still in openStreams map", streamID)
}
cont, err := fn(str)
if err != nil {
return err
@@ -69,6 +76,9 @@ func (m *streamsMap) RoundRobinIterate(fn streamLambda) error {
if !ok {
return errMapAccess
}
if str == nil {
return fmt.Errorf("BUG: Stream %d is closed, but still in openStreams map", streamID)
}
cont, err := fn(str)
m.roundRobinIndex = (m.roundRobinIndex + 1) % numStreams
if err != nil {