calculate byte length of StreamFrameQueue

This commit is contained in:
Marten Seemann
2016-05-13 11:01:59 +07:00
parent 83f71e379e
commit 16cb525dc4
2 changed files with 67 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import (
"sync"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/protocol"
)
// StreamFrameQueue is a Queue that handles StreamFrames
@@ -33,6 +34,24 @@ func (q *StreamFrameQueue) Len() int {
return len(q.prioFrames) + len(q.frames)
}
// ByteLen returns the total number of bytes queued
func (q *StreamFrameQueue) ByteLen() protocol.ByteCount {
q.mutex.Lock()
defer q.mutex.Unlock()
// TODO: improve performance
// This is a very unperformant implementation. However, the obvious solution of keeping track of the length on Push() and Pop() doesn't work, since the front frame can be split by the PacketPacker
var length protocol.ByteCount
for _, frame := range q.prioFrames {
length += protocol.ByteCount(len(frame.Data))
}
for _, frame := range q.frames {
length += protocol.ByteCount(len(frame.Data))
}
return length
}
// Pop returns the next element and deletes it from the queue
func (q *StreamFrameQueue) Pop() *frames.StreamFrame {
q.mutex.Lock()