Use pool for frames

This commit is contained in:
9seconds
2018-06-20 09:19:27 +03:00
parent 9ddf3e147c
commit c76d8307c2
8 changed files with 66 additions and 30 deletions
+24
View File
@@ -0,0 +1,24 @@
package obfuscated2
import "sync"
var framePool sync.Pool
// MakeFrame returns new pointer to the handshake frame.
func MakeFrame() *Frame {
return framePool.Get().(*Frame)
}
// ReturnFrame returns pointer to the handshake frame back to the pool.
func ReturnFrame(f *Frame) {
framePool.Put(f)
}
func init() {
framePool = sync.Pool{
New: func() interface{} {
data := make(Frame, FrameLen)
return &data
},
}
}