send retransmission in the right order

fixes #62
This commit is contained in:
Marten Seemann 2016-05-08 23:03:40 +07:00
parent 833475a2ed
commit dbcf5b8cce
3 changed files with 10 additions and 8 deletions

View file

@ -32,7 +32,7 @@ type sentPacketHandler struct {
// TODO: Move into separate class as in chromium
packetHistory map[protocol.PacketNumber]*Packet
retransmissionQueue []*Packet // ToDo: use better data structure
retransmissionQueue []*Packet
stopWaitingManager StopWaitingManager
bytesInFlight protocol.ByteCount
@ -210,8 +210,10 @@ func (h *sentPacketHandler) DequeuePacketForRetransmission() (packet *Packet) {
if len(h.retransmissionQueue) == 0 {
return nil
}
packet = h.retransmissionQueue[0]
h.retransmissionQueue = h.retransmissionQueue[1:]
queueLen := len(h.retransmissionQueue)
// packets are usually NACKed in descending order. So use the slice as a stack
packet = h.retransmissionQueue[queueLen-1]
h.retransmissionQueue = h.retransmissionQueue[:queueLen-1]
return packet
}

View file

@ -375,10 +375,10 @@ var _ = Describe("SentPacketHandler", func() {
})
It("keeps the packets in the right order", func() {
handler.nackPacket(2)
handler.nackPacket(2)
handler.nackPacket(4)
handler.nackPacket(4)
handler.nackPacket(2)
handler.nackPacket(2)
packet := handler.DequeuePacketForRetransmission()
Expect(packet.PacketNumber).To(Equal(protocol.PacketNumber(2)))
packet = handler.DequeuePacketForRetransmission()
@ -386,12 +386,12 @@ var _ = Describe("SentPacketHandler", func() {
})
It("only queues each packet once, regardless of the number of NACKs", func() {
handler.nackPacket(2)
handler.nackPacket(2)
handler.nackPacket(4)
handler.nackPacket(4)
handler.nackPacket(2)
handler.nackPacket(2)
handler.nackPacket(4)
handler.nackPacket(4)
_ = handler.DequeuePacketForRetransmission()
_ = handler.DequeuePacketForRetransmission()
Expect(handler.DequeuePacketForRetransmission()).To(BeNil())

View file

@ -333,7 +333,7 @@ func (s *Session) sendPacket() error {
// TODO: handle multiple packets retransmissions
retransmitPacket := s.sentPacketHandler.DequeuePacketForRetransmission()
if retransmitPacket != nil {
utils.Debugf("\tQueueing retransmission for packet 0x%x", retransmitPacket.PacketNumber)
utils.Debugf("\tDequeueing retransmission for packet 0x%x", retransmitPacket.PacketNumber)
s.stopWaitingManager.RegisterPacketForRetransmission(retransmitPacket)
// resend the frames that were in the packet
controlFrames = append(controlFrames, retransmitPacket.GetControlFramesForRetransmission()...)