2019-01-31 07:27:44 +00:00
|
|
|
package tcp
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
|
|
|
type pipePool struct {
|
|
|
|
pool sync.Pool
|
|
|
|
}
|
|
|
|
|
|
|
|
func newPipePool() pipePool {
|
|
|
|
return pipePool{sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return make(chan error, 1)
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pipePool) getPipe() chan error {
|
|
|
|
return p.pool.Get().(chan error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pipePool) putBackPipe(pipe chan error) {
|
2019-02-12 06:59:09 +00:00
|
|
|
p.cleanPipe(pipe)
|
2019-01-31 07:27:44 +00:00
|
|
|
p.pool.Put(pipe)
|
|
|
|
}
|
2019-02-12 06:59:09 +00:00
|
|
|
|
|
|
|
func (p *pipePool) cleanPipe(pipe chan error) {
|
|
|
|
select {
|
|
|
|
case <-pipe:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|