From b38d4b37fe7936d875f212def17a4514881050e1 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 16 Jun 2016 16:05:37 +0700 Subject: [PATCH] don't count retransmission as sent bytes for connection flow control --- stream_frame_queue.go | 5 +++-- stream_frame_queue_test.go | 14 ++++++++++++++ stream_test.go | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/stream_frame_queue.go b/stream_frame_queue.go index 284ee49b..ae00220e 100644 --- a/stream_frame_queue.go +++ b/stream_frame_queue.go @@ -148,8 +148,9 @@ func (q *streamFrameQueue) Pop(maxLength protocol.ByteCount) (*frames.StreamFram q.byteLen -= frame.DataLen() - // TODO: don't add retransmission to connection-level flow control - q.flowControlManager.AddBytesSent(streamID, frame.DataLen()) + if !isPrioFrame { + q.flowControlManager.AddBytesSent(streamID, frame.DataLen()) + } q.len-- return frame, nil diff --git a/stream_frame_queue_test.go b/stream_frame_queue_test.go index 6b2553df..34db38cd 100644 --- a/stream_frame_queue_test.go +++ b/stream_frame_queue_test.go @@ -220,6 +220,20 @@ var _ = Describe("streamFrameQueue", func() { Expect(frame).To(BeNil()) }) + It("tells the FlowControlManager how many bytes it sent", func() { + queue.Push(frame1, false) + _, err := queue.Pop(1000) + Expect(err).ToNot(HaveOccurred()) + Expect(queue.flowControlManager.(*mockFlowControlHandler).bytesSent).To(Equal(frame1.DataLen())) + }) + + It("doesn't add the bytes sent to the FlowControlManager if it was a retransmission", func() { + queue.Push(prioFrame1, true) + _, err := queue.Pop(1000) + Expect(err).ToNot(HaveOccurred()) + Expect(queue.flowControlManager.(*mockFlowControlHandler).bytesSent).To(BeZero()) + }) + It("returns normal frames if no prio frames are available", func() { queue.Push(frame1, false) queue.Push(frame2, false) diff --git a/stream_test.go b/stream_test.go index a1395981..3f284cba 100644 --- a/stream_test.go +++ b/stream_test.go @@ -46,6 +46,7 @@ type mockFlowControlHandler struct { remainingConnectionWindowSize protocol.ByteCount bytesReadForStream protocol.StreamID bytesRead protocol.ByteCount + bytesSent protocol.ByteCount highestReceivedForStream protocol.StreamID highestReceived protocol.ByteCount @@ -85,8 +86,10 @@ func (m *mockFlowControlHandler) UpdateHighestReceived(streamID protocol.StreamI } func (m *mockFlowControlHandler) AddBytesSent(streamID protocol.StreamID, n protocol.ByteCount) error { + m.bytesSent += n return nil } + func (m *mockFlowControlHandler) SendWindowSize(streamID protocol.StreamID) (protocol.ByteCount, error) { return m.sendWindowSizes[streamID], nil }