queue stream window updates directly from stream.Read

By queueing receive window updates directly from stream.Read, it is no
longer necessary to ask every stream for window updates when sending a
packet.
This commit is contained in:
Marten Seemann 2017-12-19 13:46:52 +07:00
parent 74c00a8dd8
commit c270de3538
8 changed files with 187 additions and 42 deletions

40
window_update_queue.go Normal file
View file

@ -0,0 +1,40 @@
package quic
import (
"sync"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/wire"
)
type windowUpdateQueue struct {
mutex sync.Mutex
queue map[protocol.StreamID]protocol.ByteCount
callback func(wire.Frame)
}
func newWindowUpdateQueue(cb func(wire.Frame)) *windowUpdateQueue {
return &windowUpdateQueue{
queue: make(map[protocol.StreamID]protocol.ByteCount),
callback: cb,
}
}
func (q *windowUpdateQueue) Add(stream protocol.StreamID, offset protocol.ByteCount) {
q.mutex.Lock()
q.queue[stream] = offset
q.mutex.Unlock()
}
func (q *windowUpdateQueue) QueueAll() {
q.mutex.Lock()
for stream, offset := range q.queue {
q.callback(&wire.MaxStreamDataFrame{
StreamID: stream,
ByteOffset: offset,
})
delete(q.queue, stream)
}
q.mutex.Unlock()
}