From 27f7978dad6584a83e27e3e8ed045dce8c764db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E6=89=AC?= Date: Mon, 7 Dec 2020 16:44:51 +0800 Subject: [PATCH] Fix redeliver Timer error --- Source/CocoaMQTTDeliver.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/CocoaMQTTDeliver.swift b/Source/CocoaMQTTDeliver.swift index cb87e127..c252e447 100644 --- a/Source/CocoaMQTTDeliver.swift +++ b/Source/CocoaMQTTDeliver.swift @@ -23,13 +23,16 @@ private struct InflightFrame { var timestamp: TimeInterval + var retryCount: Int + init(frame: Frame) { - self.init(frame: frame, timestamp: Date.init(timeIntervalSinceNow: 0).timeIntervalSince1970) + self.init(frame: frame, timestamp: Date.init(timeIntervalSinceNow: 0).timeIntervalSince1970, retryCount: 0) } - init(frame: Frame, timestamp: TimeInterval) { + init(frame: Frame, timestamp: TimeInterval, retryCount: Int) { self.frame = frame self.timestamp = timestamp + self.retryCount = retryCount } } @@ -210,11 +213,11 @@ extension CocoaMQTTDeliver { let nowTimestamp = Date(timeIntervalSinceNow: 0).timeIntervalSince1970 for (idx, frame) in inflight.enumerated() { - if (nowTimestamp - frame.timestamp) >= (retryTimeInterval/1000.0) { + if (nowTimestamp - frame.timestamp) >= (retryTimeInterval/1000.0) * Double(frame.retryCount) { var duplicatedFrame = frame duplicatedFrame.frame.dup = true - duplicatedFrame.timestamp = nowTimestamp + duplicatedFrame.retryCount += 1 inflight[idx] = duplicatedFrame