From fe9dd83c69e9c5ab3da38e80dd843beb4c0e9089 Mon Sep 17 00:00:00 2001 From: xtaci Date: Wed, 25 Sep 2019 20:32:27 +0800 Subject: [PATCH] adjust comments --- auxdata.go | 3 ++- kcp.go | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/auxdata.go b/auxdata.go index e9db133..89a5e8a 100644 --- a/auxdata.go +++ b/auxdata.go @@ -2,7 +2,8 @@ package kcp import "container/heap" -// a heap struct to assist send queue management +// a heap struct to assist snd_buf management +// eg: RTO type auxdata struct { sn uint32 v uint32 // value for heap comparsion diff --git a/kcp.go b/kcp.go index 739e032..c3fbf86 100644 --- a/kcp.go +++ b/kcp.go @@ -99,6 +99,8 @@ func _itimediff(later, earlier uint32) int32 { } // segment defines a KCP segment +// a segment is bound to 64Bytes to fill in +// a cache line type segment struct { conv uint32 cmd uint8 @@ -780,7 +782,7 @@ func (kcp *KCP) flush(ackOnly bool) uint32 { // check for retransmissions current := currentMs() - var change, lost, lostSegs, fastRetransSegs, earlyRetransSegs uint64 + var change, lostSegs, fastRetransSegs, earlyRetransSegs uint64 // phase 1. send new queued data ref := kcp.snd_buf[len(kcp.snd_buf)-newSegsCount : len(kcp.snd_buf)] @@ -806,7 +808,7 @@ func (kcp *KCP) flush(ackOnly bool) uint32 { // phase 2. fastacks for sn := range kcp.fastacks { needsend := false - if _itimediff(sn, kcp.snd_una) < 0 { // purge + if _itimediff(sn, kcp.snd_una) < 0 { delete(kcp.fastacks, sn) continue } @@ -856,7 +858,7 @@ func (kcp *KCP) flush(ackOnly bool) uint32 { for kcp.rto_heap.Len() > 0 { needsend := false aux := heap.Pop(kcp.rto_heap).(auxdata) - if _itimediff(aux.sn, kcp.snd_una) < 0 { // purge + if _itimediff(aux.sn, kcp.snd_una) < 0 { continue } @@ -871,9 +873,8 @@ func (kcp *KCP) flush(ackOnly bool) uint32 { } segment.resendts = current + segment.rto segment.fastack = 0 - lost++ lostSegs++ - } else { // push back the data then break + } else { kcp.rto_heap.Set(auxdata{segment.sn, segment.resendts}) break } @@ -928,7 +929,7 @@ func (kcp *KCP) flush(ackOnly bool) uint32 { } // congestion control, https://tools.ietf.org/html/rfc5681 - if lost > 0 { + if lostSegs > 0 { kcp.ssthresh = cwnd / 2 if kcp.ssthresh < IKCP_THRESH_MIN { kcp.ssthresh = IKCP_THRESH_MIN