2018-11-20 17:51:25 -05:00
|
|
|
package quic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2018-11-21 04:49:41 -05:00
|
|
|
"v2ray.com/core/common/bytespool"
|
|
|
|
|
2018-11-20 17:51:25 -05:00
|
|
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
|
|
|
)
|
|
|
|
|
2018-11-21 04:49:41 -05:00
|
|
|
var bufferPool *sync.Pool
|
2018-11-20 17:51:25 -05:00
|
|
|
|
|
|
|
func getPacketBuffer() *[]byte {
|
2018-11-21 04:49:41 -05:00
|
|
|
b := bufferPool.Get().([]byte)
|
|
|
|
return &b
|
2018-11-20 17:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func putPacketBuffer(buf *[]byte) {
|
2018-11-21 04:49:41 -05:00
|
|
|
if cap(*buf) < int(protocol.MaxReceivePacketSize) {
|
2018-11-20 17:51:25 -05:00
|
|
|
panic("putPacketBuffer called with packet of wrong size!")
|
|
|
|
}
|
2018-11-21 04:49:41 -05:00
|
|
|
bufferPool.Put(*buf)
|
2018-11-20 17:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-11-21 04:49:41 -05:00
|
|
|
bufferPool = bytespool.GetPool(protocol.MaxReceivePacketSize)
|
2018-11-20 17:51:25 -05:00
|
|
|
}
|