forked from quic-go/quic-go
refactor timer calculation in sesssion to reduce syscalls
This commit is contained in:
@@ -21,7 +21,7 @@ type SentPacketHandler interface {
|
||||
CongestionAllowsSending() bool
|
||||
CheckForError() error
|
||||
|
||||
TimeToFirstRTO() time.Duration
|
||||
TimeOfFirstRTO() time.Time
|
||||
}
|
||||
|
||||
// ReceivedPacketHandler handles ACKs needed to send for incoming packets
|
||||
|
||||
@@ -313,17 +313,15 @@ func (h *sentPacketHandler) queuePacketsRTO() {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *sentPacketHandler) TimeToFirstRTO() time.Duration {
|
||||
now := time.Now()
|
||||
min := utils.InfDuration
|
||||
func (h *sentPacketHandler) TimeOfFirstRTO() time.Time {
|
||||
var min time.Time
|
||||
for _, p := range h.packetHistory {
|
||||
if p == nil || p.Retransmitted {
|
||||
continue
|
||||
}
|
||||
if now.After(p.rtoTime) {
|
||||
return 0
|
||||
if min.IsZero() || min.After(p.rtoTime) {
|
||||
min = p.rtoTime
|
||||
}
|
||||
min = utils.MinDuration(min, p.rtoTime.Sub(now))
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
@@ -646,27 +646,20 @@ var _ = Describe("SentPacketHandler", func() {
|
||||
|
||||
Context("RTO retransmission", func() {
|
||||
Context("calculating the time to first RTO", func() {
|
||||
It("defaults to inf", func() {
|
||||
Expect(handler.TimeToFirstRTO()).To(Equal(utils.InfDuration))
|
||||
It("defaults to zero", func() {
|
||||
Expect(handler.TimeOfFirstRTO().IsZero()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("returns time to RTO", func() {
|
||||
err := handler.SentPacket(&Packet{PacketNumber: 1, Frames: []frames.Frame{}, Length: 1})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(handler.TimeToFirstRTO()).To(BeNumerically("~", protocol.DefaultRetransmissionTime, time.Millisecond))
|
||||
})
|
||||
|
||||
It("returns 0 when RTOs are required", func() {
|
||||
err := handler.SentPacket(&Packet{PacketNumber: 1, Frames: []frames.Frame{}, Length: 1})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
handler.packetHistory[1].rtoTime = time.Now().Add(-time.Second)
|
||||
Expect(handler.TimeToFirstRTO()).To(BeZero())
|
||||
Expect(handler.TimeOfFirstRTO().Sub(time.Now())).To(BeNumerically("~", protocol.DefaultRetransmissionTime, time.Millisecond))
|
||||
})
|
||||
|
||||
It("ignores nil packets", func() {
|
||||
handler.packetHistory[1] = nil
|
||||
handler.queuePacketsRTO()
|
||||
Expect(handler.TimeToFirstRTO()).To(Equal(utils.InfDuration))
|
||||
Expect(handler.TimeOfFirstRTO().IsZero()).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user