1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00

use alloc.Buffer in sending queue

This commit is contained in:
v2ray 2016-07-13 21:47:40 +02:00
parent c7b0264f9a
commit 73afe9a001
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 16 additions and 16 deletions

View File

@ -175,14 +175,14 @@ type SendingQueue struct {
start uint32
cap uint32
len uint32
list []*DataSegment
list []*alloc.Buffer
}
func NewSendingQueue(size uint32) *SendingQueue {
return &SendingQueue{
start: 0,
cap: size,
list: make([]*DataSegment, size),
list: make([]*alloc.Buffer, size),
len: 0,
}
}
@ -195,7 +195,7 @@ func (this *SendingQueue) IsEmpty() bool {
return this.len == 0
}
func (this *SendingQueue) Pop() *DataSegment {
func (this *SendingQueue) Pop() *alloc.Buffer {
if this.IsEmpty() {
return nil
}
@ -209,7 +209,7 @@ func (this *SendingQueue) Pop() *DataSegment {
return seg
}
func (this *SendingQueue) Push(seg *DataSegment) {
func (this *SendingQueue) Push(seg *alloc.Buffer) {
if this.IsFull() {
return
}
@ -326,9 +326,7 @@ func (this *SendingWorker) Push(b []byte) int {
} else {
size = len(b)
}
seg := NewDataSegment()
seg.Data = alloc.NewSmallBuffer().Clear().Append(b[:size])
this.queue.Push(seg)
this.queue.Push(alloc.NewSmallBuffer().Clear().Append(b[:size]))
b = b[size:]
nBytes += size
}
@ -395,7 +393,8 @@ func (this *SendingWorker) Flush(current uint32) {
}
for !this.queue.IsEmpty() && !this.window.IsFull() {
seg := this.queue.Pop()
seg := NewDataSegment()
seg.Data = this.queue.Pop()
seg.Number = this.nextNumber
seg.timeout = current
seg.ackSkipped = 0

View File

@ -3,6 +3,7 @@ package kcp_test
import (
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/testing/assert"
. "github.com/v2ray/v2ray-core/transport/internet/kcp"
)
@ -12,10 +13,10 @@ func TestSendingQueue(t *testing.T) {
queue := NewSendingQueue(3)
seg0 := &DataSegment{}
seg1 := &DataSegment{}
seg2 := &DataSegment{}
seg3 := &DataSegment{}
seg0 := alloc.NewBuffer()
seg1 := alloc.NewBuffer()
seg2 := alloc.NewBuffer()
seg3 := alloc.NewBuffer()
assert.Bool(queue.IsEmpty()).IsTrue()
assert.Bool(queue.IsFull()).IsFalse()
@ -44,10 +45,10 @@ func TestSendingQueueClear(t *testing.T) {
queue := NewSendingQueue(3)
seg0 := &DataSegment{}
seg1 := &DataSegment{}
seg2 := &DataSegment{}
seg3 := &DataSegment{}
seg0 := alloc.NewBuffer()
seg1 := alloc.NewBuffer()
seg2 := alloc.NewBuffer()
seg3 := alloc.NewBuffer()
queue.Push(seg0)
assert.Bool(queue.IsEmpty()).IsFalse()