Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c328918
commit 63764c4
Showing
6 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package wire | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "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) | ||
} | ||
}) | ||
}) |