add a sync.Pool of byte buffers with maximum packet size as cap

ref #217
This commit is contained in:
Lucas Clemente 2016-07-26 15:36:28 +02:00
parent 90aa8cfa95
commit 950e59fa3d
6 changed files with 56 additions and 4 deletions

26
buffer_pool_test.go Normal file
View file

@ -0,0 +1,26 @@
package quic
import (
"github.com/lucas-clemente/quic-go/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Buffer Pool", func() {
It("returns buffers of correct len and cap", func() {
buf := getPacketBuffer()
Expect(buf).To(HaveLen(0))
Expect(buf).To(HaveCap(int(protocol.MaxPacketSize)))
})
It("zeroes put buffers' length", func() {
for i := 0; i < 1000; i++ {
buf := getPacketBuffer()
putPacketBuffer(buf[0:10])
buf = getPacketBuffer()
Expect(buf).To(HaveLen(0))
Expect(buf).To(HaveCap(int(protocol.MaxPacketSize)))
}
})
})