From 34fb72e7c68b4334c175d571dd649f2ca470aff5 Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 5 Jul 2016 10:33:11 +0200 Subject: [PATCH] refine ack seg put --- transport/internet/kcp/receiving.go | 9 ++------- transport/internet/kcp/segment.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index b281441a..56bfee6c 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -202,15 +202,10 @@ func (this *AckList) Clear(una uint32) { func (this *AckList) Flush(current uint32, rto uint32) { seg := NewAckSegment() this.Lock() - for i := 0; i < len(this.numbers); i++ { + for i := 0; i < len(this.numbers) && !seg.IsFull(); i++ { if this.nextFlush[i] <= current { - seg.Count++ - seg.NumberList = append(seg.NumberList, this.numbers[i]) - seg.TimestampList = append(seg.TimestampList, this.timestamps[i]) + seg.PutNumber(this.numbers[i], this.timestamps[i]) this.nextFlush[i] = current + rto/2 - if seg.Count == 128 { - break - } } } this.Unlock() diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 1cbbb18a..1e1b20cf 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -109,6 +109,16 @@ func NewAckSegment() *AckSegment { return seg } +func (this *AckSegment) PutNumber(number uint32, timestamp uint32) { + this.Count++ + this.NumberList = append(this.NumberList, number) + this.TimestampList = append(this.TimestampList, timestamp) +} + +func (this *AckSegment) IsFull() bool { + return this.Count == 128 +} + func (this *AckSegment) ByteSize() int { return 2 + 1 + 1 + 4 + 4 + 1 + int(this.Count)*4 + int(this.Count)*4 }