소스 검색

refine ack seg put

v2ray 9 년 전
부모
커밋
34fb72e7c6
2개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 2 7
      transport/internet/kcp/receiving.go
  2. 10 0
      transport/internet/kcp/segment.go

+ 2 - 7
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()

+ 10 - 0
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
 }