Fix pool to uint from int
This commit is contained in:
@@ -7,12 +7,12 @@ import (
|
|||||||
|
|
||||||
func TestRetrieveBufferOfRequestedSize(t *testing.T) {
|
func TestRetrieveBufferOfRequestedSize(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
size := 1024
|
size := 1024
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
|
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Fatalf("Expected buffer, got nil")
|
t.Fatalf("Expected buffer, got nil")
|
||||||
@@ -25,12 +25,12 @@ func TestRetrieveBufferOfRequestedSize(t *testing.T) {
|
|||||||
|
|
||||||
func TestRequestBufferSizeZero(t *testing.T) {
|
func TestRequestBufferSizeZero(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
size := 0
|
size := 0
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
|
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Fatalf("Expected buffer, got nil")
|
t.Fatalf("Expected buffer, got nil")
|
||||||
@@ -43,7 +43,7 @@ func TestRequestBufferSizeZero(t *testing.T) {
|
|||||||
|
|
||||||
func TestConcurrentAccessToBufferPool(t *testing.T) {
|
func TestConcurrentAccessToBufferPool(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ func TestConcurrentAccessToBufferPool(t *testing.T) {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Errorf("Expected buffer, got nil")
|
t.Errorf("Expected buffer, got nil")
|
||||||
}
|
}
|
||||||
@@ -70,12 +70,12 @@ func TestConcurrentAccessToBufferPool(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetBufferLockUnlock(t *testing.T) {
|
func TestGetBufferLockUnlock(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
size := 1024
|
size := 1024
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
|
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Fatalf("Expected buffer, got nil")
|
t.Fatalf("Expected buffer, got nil")
|
||||||
@@ -88,12 +88,12 @@ func TestGetBufferLockUnlock(t *testing.T) {
|
|||||||
|
|
||||||
func TestVerifyPoolCreationForNewSizes(t *testing.T) {
|
func TestVerifyPoolCreationForNewSizes(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
size := 512
|
size := 512
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
|
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Fatalf("Expected buffer, got nil")
|
t.Fatalf("Expected buffer, got nil")
|
||||||
@@ -106,12 +106,12 @@ func TestVerifyPoolCreationForNewSizes(t *testing.T) {
|
|||||||
|
|
||||||
func TestBufferPoolManagerGetBuffer(t *testing.T) {
|
func TestBufferPoolManagerGetBuffer(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
size := 1024
|
size := 1024
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
|
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Fatalf("Expected buffer, got nil")
|
t.Fatalf("Expected buffer, got nil")
|
||||||
@@ -124,13 +124,13 @@ func TestBufferPoolManagerGetBuffer(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetBufferWithMultipleSizes(t *testing.T) {
|
func TestGetBufferWithMultipleSizes(t *testing.T) {
|
||||||
bpm := &BufferPoolManager{
|
bpm := &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
sizes := []int{512, 1024, 2048}
|
sizes := []int{512, 1024, 2048}
|
||||||
for _, size := range sizes {
|
for _, size := range sizes {
|
||||||
buffer := bpm.GetBuffer(size)
|
buffer := bpm.GetBuffer(uint(size))
|
||||||
|
|
||||||
if buffer == nil {
|
if buffer == nil {
|
||||||
t.Fatalf("Expected buffer for size %d, got nil", size)
|
t.Fatalf("Expected buffer for size %d, got nil", size)
|
||||||
|
@@ -3,6 +3,6 @@ package pdu
|
|||||||
import "sync"
|
import "sync"
|
||||||
|
|
||||||
var ByteBufferPool = &BufferPoolManager{
|
var ByteBufferPool = &BufferPoolManager{
|
||||||
pools: make(map[int]*sync.Pool),
|
pools: make(map[uint]*sync.Pool),
|
||||||
mu: sync.Mutex{},
|
mu: sync.Mutex{},
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (p *PDU_HEADER) Encode() (*[]uint8, error) {
|
func (p *PDU_HEADER) Encode() (*[]uint8, error) {
|
||||||
buf := ByteBufferPool.GetBuffer(int(p.Size()))
|
buf := ByteBufferPool.GetBuffer(uint(p.Size()))
|
||||||
err := p.EncodeInto(buf)
|
err := p.EncodeInto(buf)
|
||||||
return buf, err
|
return buf, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user