1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-14 07:58:16 -04:00
v2fly/vendor/github.com/lucas-clemente/quic-go/buffer_pool.go

28 lines
489 B
Go
Raw Normal View History

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
}