From 829355e6bf520328ce846c977dd391bf35e409b0 Mon Sep 17 00:00:00 2001 From: v2ray Date: Fri, 1 Jul 2016 15:54:04 +0200 Subject: [PATCH] correctly calculate len of sending window --- transport/internet/kcp/sending.go | 2 +- transport/internet/kcp/sending_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 2a761ef73..d6e2c1d73 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -61,7 +61,7 @@ func (this *SendingWindow) Remove(idx uint32) { seg.Release() this.data[pos] = nil if pos == this.start { - if this.len == 1 { + if this.start == this.last { this.len = 0 this.start = 0 this.last = 0 diff --git a/transport/internet/kcp/sending_test.go b/transport/internet/kcp/sending_test.go index d6f1539f0..2cb4c8fd0 100644 --- a/transport/internet/kcp/sending_test.go +++ b/transport/internet/kcp/sending_test.go @@ -94,4 +94,15 @@ func TestSendingWindow(t *testing.T) { }) assert.Int(window.Len()).Equals(1) assert.Uint32(window.First().Number).Equals(4) + + window.Push(&DataSegment{ + Number: 5, + }) + assert.Int(window.Len()).Equals(2) + + window.Remove(1) + assert.Int(window.Len()).Equals(2) + + window.Remove(0) + assert.Int(window.Len()).Equals(0) }