refine ack seg put

pull/215/head
v2ray 9 years ago
parent 13e83c17a5
commit 34fb72e7c6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -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()

@ -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
}

Loading…
Cancel
Save