cloudflared/proxy/pool.go
cthuang e22422aafb TUN-5749: Refactor cloudflared to pave way for reconfigurable ingress
- Split origin into supervisor and proxy packages
- Create configManager to handle dynamic config
2022-02-14 15:37:09 +00:00

30 lines
480 B
Go

package proxy
import (
"sync"
)
type bufferPool struct {
// A bufferPool must not be copied after first use.
// https://golang.org/pkg/sync/#Pool
buffers sync.Pool
}
func newBufferPool(bufferSize int) *bufferPool {
return &bufferPool{
buffers: sync.Pool{
New: func() interface{} {
return make([]byte, bufferSize)
},
},
}
}
func (p *bufferPool) Get() []byte {
return p.buffers.Get().([]byte)
}
func (p *bufferPool) Put(buf []byte) {
p.buffers.Put(buf)
}