From 2169dcd7dabfb41f2d937d260735a205eafc2396 Mon Sep 17 00:00:00 2001 From: v2ray Date: Fri, 1 Jul 2016 22:54:59 +0200 Subject: [PATCH] fix a bug in length calculation --- transport/internet/kcp/sending.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index d6e2c1d7..d2c89137 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -60,16 +60,17 @@ func (this *SendingWindow) Remove(idx uint32) { } seg.Release() this.data[pos] = nil - if pos == this.start { - if this.start == this.last { - this.len = 0 - this.start = 0 - this.last = 0 - } else { - delta := this.next[pos] - this.start - this.start = this.next[pos] - this.len -= delta + if pos == this.start && pos == this.last { + this.len = 0 + this.start = 0 + this.last = 0 + } else if pos == this.start { + delta := this.next[pos] - this.start + if this.next[pos] < this.start { + delta = this.next[pos] + this.cap - this.start } + this.start = this.next[pos] + this.len -= delta } else if pos == this.last { this.last = this.prev[pos] } else {