9 type bufferPool struct {
10 // limiter has a "true" placeholder for each in-use buffer.
12 // Pool has unused buffers.
16 func newBufferPool(count int, bufSize int) *bufferPool {
18 p.New = func() interface{} {
19 return make([]byte, bufSize)
21 p.limiter = make(chan bool, count)
25 func (p *bufferPool) Get(size int) []byte {
27 case p.limiter <- true:
30 log.Printf("reached max buffers (%d), waiting", cap(p.limiter))
32 log.Printf("waited %v for a buffer", time.Since(t0))
34 buf := p.Pool.Get().([]byte)
36 log.Fatalf("bufferPool Get(size=%d) but max=%d", size, cap(buf))
41 func (p *bufferPool) Put(buf []byte) {