This repository has been archived on 2022-07-30. You can view files and clone it, but cannot push or open issues/pull-requests.
2022-07-29 19:36:42 +00:00
|
|
|
package kvstore
|
|
|
|
|
2022-07-30 03:58:35 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2022-07-29 19:36:42 +00:00
|
|
|
|
|
|
|
var (
|
2022-07-30 03:58:35 +00:00
|
|
|
connTimeout = 16 * time.Second
|
|
|
|
pollInterval = 500 * time.Millisecond
|
|
|
|
modQSize = 1024
|
|
|
|
|
|
|
|
bufferPool = make(chan []byte, 1024)
|
|
|
|
poolBufSize = 4096
|
2022-07-29 19:36:42 +00:00
|
|
|
)
|
2022-07-30 03:58:35 +00:00
|
|
|
|
|
|
|
func GetDataBuf(size int) []byte {
|
|
|
|
if size > poolBufSize {
|
|
|
|
return make([]byte, size)
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case b := <-bufferPool:
|
|
|
|
return b[:size]
|
|
|
|
default:
|
|
|
|
return make([]byte, poolBufSize)[:size]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RecycleDataBuf(b []byte) {
|
|
|
|
if cap(b) != poolBufSize {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case bufferPool <- b:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|