1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-30 07:46:41 -04: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 start uint32
cap uint32 cap uint32
len uint32 len uint32
list []*DataSegment list []*alloc.Buffer
} }
func NewSendingQueue(size uint32) *SendingQueue { func NewSendingQueue(size uint32) *SendingQueue {
return &SendingQueue{ return &SendingQueue{
start: 0, start: 0,
cap: size, cap: size,
list: make([]*DataSegment, size), list: make([]*alloc.Buffer, size),
len: 0, len: 0,
} }
} }
@ -195,7 +195,7 @@ func (this *SendingQueue) IsEmpty() bool {
return this.len == 0 return this.len == 0
} }
func (this *SendingQueue) Pop() *DataSegment { func (this *SendingQueue) Pop() *alloc.Buffer {
if this.IsEmpty() { if this.IsEmpty() {
return nil return nil
} }
@ -209,7 +209,7 @@ func (this *SendingQueue) Pop() *DataSegment {
return seg return seg
} }
func (this *SendingQueue) Push(seg *DataSegment) { func (this *SendingQueue) Push(seg *alloc.Buffer) {
if this.IsFull() { if this.IsFull() {
return return
} }
@ -326,9 +326,7 @@ func (this *SendingWorker) Push(b []byte) int {
} else { } else {
size = len(b) size = len(b)
} }
seg := NewDataSegment() this.queue.Push(alloc.NewSmallBuffer().Clear().Append(b[:size]))
seg.Data = alloc.NewSmallBuffer().Clear().Append(b[:size])
this.queue.Push(seg)
b = b[size:] b = b[size:]
nBytes += size nBytes += size
} }
@ -395,7 +393,8 @@ func (this *SendingWorker) Flush(current uint32) {
} }
for !this.queue.IsEmpty() && !this.window.IsFull() { for !this.queue.IsEmpty() && !this.window.IsFull() {
seg := this.queue.Pop() seg := NewDataSegment()
seg.Data = this.queue.Pop()
seg.Number = this.nextNumber seg.Number = this.nextNumber
seg.timeout = current seg.timeout = current
seg.ackSkipped = 0 seg.ackSkipped = 0

View File

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