mirror of https://github.com/pkg/sftp.git
30 lines
382 B
Go
30 lines
382 B
Go
package sftp
|
|
|
|
type bufPool struct {
|
|
ch chan []byte
|
|
blen int
|
|
}
|
|
|
|
func newBufPool(depth, bufLen int) *bufPool {
|
|
return &bufPool{
|
|
ch: make(chan []byte, depth),
|
|
blen: bufLen,
|
|
}
|
|
}
|
|
|
|
func (p *bufPool) Get() []byte {
|
|
select {
|
|
case b := <-p.ch:
|
|
return b
|
|
default:
|
|
return make([]byte, p.blen)
|
|
}
|
|
}
|
|
|
|
func (p *bufPool) Put(b []byte) {
|
|
select {
|
|
case p.ch <- b:
|
|
default:
|
|
}
|
|
}
|