add go-tun2socks code

This commit is contained in:
Jason
2019-07-16 11:37:52 +08:00
parent 828ba9948d
commit 6d01dec5a4
301 changed files with 69694 additions and 1 deletions

35
core/buffer_pool.go Normal file
View File

@@ -0,0 +1,35 @@
package core
import (
"sync"
)
var pool *sync.Pool
const BufSize = 2 * 1024
func SetBufferPool(p *sync.Pool) {
pool = p
}
func NewBytes(size int) []byte {
if size <= BufSize {
return pool.Get().([]byte)
} else {
return make([]byte, size)
}
}
func FreeBytes(b []byte) {
if len(b) >= BufSize {
pool.Put(b)
}
}
func init() {
SetBufferPool(&sync.Pool{
New: func() interface{} {
return make([]byte, BufSize)
},
})
}