add method to ask SendPacketHandler if any retransmissions queued

This commit is contained in:
Marten Seemann
2016-05-13 12:56:58 +07:00
parent 16cb525dc4
commit f8dc78967a
4 changed files with 21 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ type SentPacketHandler interface {
SentPacket(packet *Packet) error
ReceivedAck(ackFrame *frames.AckFrame) (time.Duration, []*Packet, []*Packet, error)
HasPacketForRetransmission() bool
DequeuePacketForRetransmission() (packet *Packet)
BytesInFlight() protocol.ByteCount

View File

@@ -206,10 +206,18 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *frames.AckFrame) (time.Duratio
return timeDelta, ackedPackets, lostPackets, nil
}
func (h *sentPacketHandler) HasPacketForRetransmission() bool {
if len(h.retransmissionQueue) > 0 {
return true
}
return false
}
func (h *sentPacketHandler) DequeuePacketForRetransmission() (packet *Packet) {
if len(h.retransmissionQueue) == 0 {
if !h.HasPacketForRetransmission() {
return nil
}
queueLen := len(h.retransmissionQueue)
// packets are usually NACKed in descending order. So use the slice as a stack
packet = h.retransmissionQueue[queueLen-1]

View File

@@ -365,9 +365,16 @@ var _ = Describe("SentPacketHandler", func() {
Expect(handler.BytesInFlight()).To(Equal(protocol.ByteCount(6)))
})
It("does not dequeue a packet if no packet has been nacked", func() {
handler.nackPacket(2)
Expect(handler.HasPacketForRetransmission()).To(BeFalse())
Expect(handler.DequeuePacketForRetransmission()).To(BeNil())
})
It("queues a packet for retransmission", func() {
handler.nackPacket(2)
handler.nackPacket(2)
Expect(handler.HasPacketForRetransmission()).To(BeTrue())
Expect(len(handler.retransmissionQueue)).To(Equal(1))
Expect(handler.retransmissionQueue[0].PacketNumber).To(Equal(protocol.PacketNumber(2)))
})

View File

@@ -27,6 +27,10 @@ func (h *mockSentPacketHandler) DequeuePacketForRetransmission() (packet *ackhan
return nil
}
func (h *mockSentPacketHandler) HasPacketForRetransmission() bool {
return false
}
func (h *mockSentPacketHandler) BytesInFlight() protocol.ByteCount {
return 0
}