diff --git a/transport/internet/kcp/kcp.go b/transport/internet/kcp/kcp.go index bd654411..e6f563aa 100644 --- a/transport/internet/kcp/kcp.go +++ b/transport/internet/kcp/kcp.go @@ -9,10 +9,6 @@ import ( "github.com/v2ray/v2ray-core/common/log" ) -func _itimediff(later, earlier uint32) int32 { - return (int32)(later - earlier) -} - type State int const ( @@ -178,7 +174,7 @@ func (kcp *KCP) flush() { if kcp.state == StateTerminated { return } - if kcp.state == StateActive && _itimediff(kcp.current, kcp.lastPayloadTime) >= 30000 { + if kcp.state == StateActive && kcp.current-kcp.lastPayloadTime >= 30000 { kcp.OnClose() } @@ -189,13 +185,13 @@ func (kcp *KCP) flush() { }) kcp.output.Flush() - if _itimediff(kcp.current, kcp.stateBeginTime) > 8000 { + if kcp.current-kcp.stateBeginTime > 8000 { kcp.SetState(StateTerminated) } return } - if kcp.state == StateReadyToClose && _itimediff(kcp.current, kcp.stateBeginTime) > 15000 { + if kcp.state == StateReadyToClose && kcp.current-kcp.stateBeginTime > 15000 { kcp.SetState(StateTerminating) } @@ -203,7 +199,7 @@ func (kcp *KCP) flush() { kcp.receivingWorker.Flush() kcp.sendingWorker.Flush() - if kcp.sendingWorker.PingNecessary() || kcp.receivingWorker.PingNecessary() || _itimediff(kcp.current, kcp.lastPingTime) >= 5000 { + if kcp.sendingWorker.PingNecessary() || kcp.receivingWorker.PingNecessary() || kcp.current-kcp.lastPingTime >= 5000 { seg := NewCmdOnlySegment() seg.Conv = kcp.conv seg.Cmd = SegmentCommandPing diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 5c1c7fa5..9c5ad6c8 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -108,7 +108,7 @@ func (this *SendingWindow) HandleFastAck(number uint32) { for i := this.start; ; i = this.next[i] { seg := this.data[i] - if _itimediff(number, seg.Number) < 0 { + if number-seg.Number > 0x7FFFFFFF { break } if number != seg.Number { @@ -136,7 +136,7 @@ func (this *SendingWindow) Flush(current uint32, resend uint32, rto uint32, maxI segment.transmit++ segment.timeout = current + rto this.totalInFlightSize++ - } else if _itimediff(current, segment.timeout) >= 0 { + } else if current-segment.timeout < 0x7FFFFFFF { needsend = true segment.transmit++ segment.timeout = current + rto