Skip to content

Commit 0d160f9

Browse files
Apply suggestions from code review
Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent f85fc51 commit 0d160f9

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ NS_ASSUME_NONNULL_BEGIN
224224
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion;
225225

226226
/**
227-
* Returns YES if the MTRDevice corrresponding to the given node ID is a thread device, NO otherwise.
227+
* Returns YES if the MTRDevice corrresponding to the given node ID is known to be a thread device, NO otherwise.
228228
*/
229-
- (BOOL)usesThreadForDevice:(chip::NodeId)nodeID;
229+
- (BOOL)definitelyUsesThreadForDevice:(chip::NodeId)nodeID;
230230

231231
/**
232232
* Will return chip::kUndefinedFabricIndex if we do not have a fabric index.

src/darwin/Framework/CHIP/MTROTAImageTransferHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class MTROTAImageTransferHandler : public chip::bdx::AsyncResponder {
7575

7676
bool mNeedToCallTransferSessionEnd = false;
7777

78-
bool mIsPeerNodeAThreadDevice = NO;
78+
bool mIsPeerNodeAKnownThreadDevice = NO;
7979
};
8080

8181
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/MTROTAImageTransferHandler.mm

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
// Timeout for the BDX transfer session. The OTA Spec mandates this should be >= 5 minutes.
3434
constexpr System::Clock::Timeout kBdxTimeout = System::Clock::Seconds16(5 * 60);
3535

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);
4040

4141
constexpr bdx::TransferRole kBdxRole = bdx::TransferRole::kSender;
4242

@@ -245,7 +245,7 @@ - (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *
245245
// For thread devices, we need to throttle sending the response to BlockQuery, if the query is processed, before kBdxThrottleIntervalInMsecs
246246
// has elapsed to prevent the BDX messages spamming up the network. Get the timestamp at which we start processing the BlockQuery message.
247247

248-
__block uint64_t startBlockQueryHandlingTimestamp = chip::System::SystemClock().GetMonotonicMilliseconds64().count();
248+
auto startBlockQueryHandlingTimestamp = System::SystemClock().GetMonotonicTimestamp()
249249

250250
auto blockSize = @(mTransfer.GetTransferBlockSize());
251251
auto blockIndex = @(mTransfer.GetNextBlockNum());
@@ -294,12 +294,12 @@ - (instancetype)initWithMTROTAImageTransferHandler:(MTROTAImageTransferHandler *
294294

295295
if (mIsPeerNodeAThreadDevice) {
296296
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) {
299299
completionHandler = respondWithBlock;
300300
} 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());
303303
dispatch_after(time, dispatch_get_main_queue(), ^{
304304
respondWithBlock(data, isEOF);
305305
});

0 commit comments

Comments
 (0)