flush when input has make a window slide

This commit is contained in:
xtaci
2020-07-01 18:04:55 +08:00
parent b7b732f98f
commit 43d2c47d8a
+10 -2
View File
@@ -441,7 +441,7 @@ func (kcp *KCP) parse_fastack(sn, ts uint32) {
}
}
func (kcp *KCP) parse_una(una uint32) {
func (kcp *KCP) parse_una(una uint32) int {
count := 0
for k := range kcp.snd_buf {
seg := &kcp.snd_buf[k]
@@ -455,6 +455,7 @@ func (kcp *KCP) parse_una(una uint32) {
if count > 0 {
kcp.snd_buf = kcp.remove_front(kcp.snd_buf, count)
}
return count
}
// ack append
@@ -534,6 +535,7 @@ func (kcp *KCP) Input(data []byte, regular, ackNoDelay bool) int {
var latest uint32 // the latest ack packet
var flag int
var inSegs uint64
var windowSlides bool
for {
var ts, sn, length, una, conv uint32
@@ -569,7 +571,9 @@ func (kcp *KCP) Input(data []byte, regular, ackNoDelay bool) int {
if regular {
kcp.rmt_wnd = uint32(wnd)
}
kcp.parse_una(una)
if kcp.parse_una(una) > 0 {
windowSlides = true
}
kcp.shrink_buf()
if cmd == IKCP_CMD_ACK {
@@ -650,6 +654,10 @@ func (kcp *KCP) Input(data []byte, regular, ackNoDelay bool) int {
}
}
if windowSlides { // if window has slided, flush
kcp.flush(false)
}
if ackNoDelay && len(kcp.acklist) > 0 { // ack immediately
kcp.flush(true)
}