2017-05-27 14:30:11 -05:00
|
|
|
package quic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2018-02-17 00:29:53 -05:00
|
|
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
2017-05-27 14:30:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var bufferPool sync.Pool
|
|
|
|
|
2018-03-25 23:37:41 -05:00
|
|
|
func getPacketBuffer() *[]byte {
|
|
|
|
return bufferPool.Get().(*[]byte)
|
2017-05-27 14:30:11 -05:00
|
|
|
}
|
|
|
|
|
2018-03-25 23:37:41 -05:00
|
|
|
func putPacketBuffer(buf *[]byte) {
|
|
|
|
if cap(*buf) != int(protocol.MaxReceivePacketSize) {
|
2017-05-27 14:30:11 -05:00
|
|
|
panic("putPacketBuffer called with packet of wrong size!")
|
|
|
|
}
|
2018-03-25 23:37:41 -05:00
|
|
|
bufferPool.Put(buf)
|
2017-05-27 14:30:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
bufferPool.New = func() interface{} {
|
2018-03-25 23:37:41 -05:00
|
|
|
b := make([]byte, 0, protocol.MaxReceivePacketSize)
|
|
|
|
return &b
|
2017-05-27 14:30:11 -05:00
|
|
|
}
|
|
|
|
}
|