Quellcode durchsuchen

correctly calculate len of sending window

v2ray vor 9 Jahren
Ursprung
Commit
829355e6bf
2 geänderte Dateien mit 12 neuen und 1 gelöschten Zeilen
  1. 1 1
      transport/internet/kcp/sending.go
  2. 11 0
      transport/internet/kcp/sending_test.go

+ 1 - 1
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

+ 11 - 0
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)
 }