forked from quic-go/quic-go
use the same ACK frame struct in the send path, remove ACK frame pool (#3831)
This commit is contained in:
@@ -169,16 +169,18 @@ func (h *receivedPacketTracker) GetAckFrame(onlyIfQueued bool) *wire.AckFrame {
|
||||
}
|
||||
}
|
||||
|
||||
ack := wire.GetAckFrame()
|
||||
// This function always returns the same ACK frame struct, filled with the most recent values.
|
||||
ack := h.lastAck
|
||||
if ack == nil {
|
||||
ack = &wire.AckFrame{}
|
||||
}
|
||||
ack.Reset()
|
||||
ack.DelayTime = utils.Max(0, now.Sub(h.largestObservedReceivedTime))
|
||||
ack.ECT0 = h.ect0
|
||||
ack.ECT1 = h.ect1
|
||||
ack.ECNCE = h.ecnce
|
||||
ack.AckRanges = h.packetHistory.AppendAckRanges(ack.AckRanges)
|
||||
|
||||
if h.lastAck != nil {
|
||||
wire.PutAckFrame(h.lastAck)
|
||||
}
|
||||
h.lastAck = ack
|
||||
h.ackAlarm = time.Time{}
|
||||
h.ackQueued = false
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package wire
|
||||
|
||||
import "sync"
|
||||
|
||||
var ackFramePool = sync.Pool{New: func() any {
|
||||
return &AckFrame{}
|
||||
}}
|
||||
|
||||
func GetAckFrame() *AckFrame {
|
||||
f := ackFramePool.Get().(*AckFrame)
|
||||
f.AckRanges = f.AckRanges[:0]
|
||||
f.ECNCE = 0
|
||||
f.ECT0 = 0
|
||||
f.ECT1 = 0
|
||||
f.DelayTime = 0
|
||||
return f
|
||||
}
|
||||
|
||||
func PutAckFrame(f *AckFrame) {
|
||||
if cap(f.AckRanges) > 4 {
|
||||
return
|
||||
}
|
||||
ackFramePool.Put(f)
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package wire
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("ACK Frame (for IETF QUIC)", func() {
|
||||
It("gets an ACK frame from the pool", func() {
|
||||
for i := 0; i < 100; i++ {
|
||||
ack := GetAckFrame()
|
||||
Expect(ack.AckRanges).To(BeEmpty())
|
||||
Expect(ack.ECNCE).To(BeZero())
|
||||
Expect(ack.ECT0).To(BeZero())
|
||||
Expect(ack.ECT1).To(BeZero())
|
||||
Expect(ack.DelayTime).To(BeZero())
|
||||
|
||||
ack.AckRanges = make([]AckRange, rand.Intn(10))
|
||||
ack.ECNCE = 1
|
||||
ack.ECT0 = 2
|
||||
ack.ECT1 = 3
|
||||
ack.DelayTime = time.Hour
|
||||
PutAckFrame(ack)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user