|
33 | 33 | // Timeout for the BDX transfer session. The OTA Spec mandates this should be >= 5 minutes.
|
34 | 34 | constexpr System::Clock::Timeout kBdxTimeout = System::Clock::Seconds16(5 * 60);
|
35 | 35 |
|
36 |
| -// For thread devices, we need to throttle sending Blocks in response to BlockQuery messages |
37 |
| -// to avoid spamming the network with too many BDX messages. We are going to match the polling |
38 |
| -// interval of 50 ms as the time to wait before sending a Block in response to a BlockQuery. |
39 |
| -constexpr System::Clock::Timeout kBdxThrottleIntervalInMsecs = System::Clock::Milliseconds32(50); |
| 36 | +// For thread devices, we may want to throttle sending Blocks in response to BlockQuery messages |
| 37 | +// to avoid spamming the network with too many BDX messages. For now, match the old 50ms |
| 38 | +// polling interval we used to have. |
| 39 | +constexpr auto kBdxThrottleInterval = System::Clock::Milliseconds32(50); |
40 | 40 |
|
41 | 41 | constexpr bdx::TransferRole kBdxRole = bdx::TransferRole::kSender;
|
42 | 42 |
|
@@ -245,7 +245,7 @@ - (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *
|
245 | 245 | // For thread devices, we need to throttle sending the response to BlockQuery, if the query is processed, before kBdxThrottleIntervalInMsecs
|
246 | 246 | // has elapsed to prevent the BDX messages spamming up the network. Get the timestamp at which we start processing the BlockQuery message.
|
247 | 247 |
|
248 |
| - __block uint64_t startBlockQueryHandlingTimestamp = chip::System::SystemClock().GetMonotonicMilliseconds64().count(); |
| 248 | + auto startBlockQueryHandlingTimestamp = System::SystemClock().GetMonotonicTimestamp() |
249 | 249 |
|
250 | 250 | auto blockSize = @(mTransfer.GetTransferBlockSize());
|
251 | 251 | auto blockIndex = @(mTransfer.GetNextBlockNum());
|
@@ -294,12 +294,12 @@ - (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *
|
294 | 294 |
|
295 | 295 | if (mIsPeerNodeAThreadDevice) {
|
296 | 296 | completionHandler = ^(NSData * _Nullable data, BOOL isEOF) {
|
297 |
| - uint64_t timeElapsed = chip::System::SystemClock().GetMonotonicMilliseconds64().count() - startBlockQueryHandlingTimestamp; |
298 |
| - if (timeElapsed >= kBdxThrottleIntervalInMsecs.count()) { |
| 297 | + auto timeElapsed = System::SystemClock().GetMonotonicTimestamp - startBlockQueryHandlingTimestamp; |
| 298 | + if (timeElapsed >= kBdxThrottleIntervalInMsecs) { |
299 | 299 | completionHandler = respondWithBlock;
|
300 | 300 | } else {
|
301 |
| - double timeRemainingInSecs = (kBdxThrottleIntervalInMsecs.count() - timeElapsed) / kMilliSecondsInSecond; |
302 |
| - dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t) (timeRemainingInSecs * NSEC_PER_SEC)); |
| 301 | + auto timeRemaining = std::chrono::duration_cast<std::chrono::nanoseconds>(kBdxThrottleIntervalInMsecs - timeElapsed); |
| 302 | + dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, timeRemaining.count()); |
303 | 303 | dispatch_after(time, dispatch_get_main_queue(), ^{
|
304 | 304 | respondWithBlock(data, isEOF);
|
305 | 305 | });
|
|
0 commit comments