From 6e615c5863d85959c66c35eb19be3486e064f6a7 Mon Sep 17 00:00:00 2001 From: v2ray Date: Wed, 29 Jun 2016 14:49:49 +0200 Subject: [PATCH] correctly measure payload time --- transport/internet/kcp/kcp.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transport/internet/kcp/kcp.go b/transport/internet/kcp/kcp.go index 48598623a..6aa8c7252 100644 --- a/transport/internet/kcp/kcp.go +++ b/transport/internet/kcp/kcp.go @@ -67,6 +67,7 @@ type KCP struct { state State stateBeginTime uint32 lastIncomingTime uint32 + lastPayloadTime uint32 sendingUpdated bool receivingUpdated bool lastPingTime uint32 @@ -325,6 +326,7 @@ func (kcp *KCP) Input(data []byte) int { kcp.shrink_buf() kcp.acklist.Add(seg.Number, seg.Timestamp) kcp.parse_data(seg) + kcp.lastPayloadTime = kcp.current case *ACKSegment: kcp.HandleOption(seg.Opt) if kcp.rmt_wnd < seg.ReceivingWindow { @@ -346,6 +348,7 @@ func (kcp *KCP) Input(data []byte) int { } } kcp.shrink_buf() + kcp.lastPayloadTime = kcp.current case *CmdOnlySegment: kcp.HandleOption(seg.Opt) if seg.Cmd == SegmentCommandTerminated { @@ -377,7 +380,7 @@ func (kcp *KCP) flush() { if kcp.state == StateTerminated { return } - if kcp.state == StateActive && _itimediff(kcp.current, kcp.lastIncomingTime) >= 30000 { + if kcp.state == StateActive && _itimediff(kcp.current, kcp.lastPayloadTime) >= 30000 { kcp.OnClose() }