Cleanup pools from wrappes

This commit is contained in:
9seconds
2020-08-10 13:29:08 +03:00
parent 95b16cd805
commit 86a8f69273
9 changed files with 14 additions and 89 deletions
+1 -3
View File
@@ -88,9 +88,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
return nil
case packetLength < clientAbridgedLargePacketLength:
length24 := utils.ToUint24(uint32(packetLength))
buf := acquireClientBytesBuffer()
defer releaseClientBytesBuffer(buf)
buf := bytes.Buffer{}
buf.WriteByte(byte(clientAbridgedSmallPacketLength))
buf.Write(length24[:])
@@ -1,6 +1,7 @@
package packetack
import (
"bytes"
"encoding/binary"
"fmt"
"math/rand"
@@ -34,10 +35,9 @@ func (w *wrapperClientIntermediateSecure) Write(packet conntypes.Packet, acks *c
return nil
}
buf := acquireClientBytesBuffer()
defer releaseClientBytesBuffer(buf)
buf := &bytes.Buffer{}
paddingLength := rand.Intn(4)
buf.Grow(4 + len(packet) + paddingLength)
binary.Write(buf, binary.LittleEndian, uint32(len(packet)+paddingLength)) // nolint: errcheck
-23
View File
@@ -1,23 +0,0 @@
package packetack
import (
"bytes"
"sync"
)
var (
poolClientBytesBuffer = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
)
func acquireClientBytesBuffer() *bytes.Buffer {
return poolClientBytesBuffer.Get().(*bytes.Buffer)
}
func releaseClientBytesBuffer(buf *bytes.Buffer) {
buf.Reset()
poolClientBytesBuffer.Put(buf)
}