From 107634882beab99bfd3fa8ec7da96d5a51aa0f2f Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Fri, 3 Dec 2021 01:15:02 +0800 Subject: [PATCH] Use Loop::Break/Continue instead of bool in visitor of ForEachActiveObject (#12420) --- src/app/CASESessionManager.cpp | 8 ++-- src/app/InteractionModelEngine.cpp | 8 ++-- src/channel/Manager.cpp | 4 +- src/channel/Manager.h | 6 +-- src/controller/CHIPDeviceController.cpp | 8 ++-- src/inet/InetLayer.h | 8 ++-- src/inet/TCPEndPoint.cpp | 12 +++--- src/lib/support/Pool.cpp | 19 +++++----- src/lib/support/Pool.h | 42 +++++++++++++-------- src/lib/support/PoolWrapper.h | 14 ++++--- src/lib/support/tests/TestPool.cpp | 16 ++++---- src/messaging/ExchangeMgr.cpp | 10 ++--- src/messaging/ReliableMessageMgr.cpp | 22 +++++------ src/messaging/ReliableMessageMgr.h | 2 +- src/transport/SecureSessionTable.h | 8 ++-- src/transport/SessionManager.cpp | 20 +++++----- src/transport/SessionManager.h | 12 +++--- src/transport/UnauthenticatedSessionTable.h | 6 +-- src/transport/raw/TCP.cpp | 6 +-- 19 files changed, 123 insertions(+), 108 deletions(-) diff --git a/src/app/CASESessionManager.cpp b/src/app/CASESessionManager.cpp index f5c76239b2a04c..19cc27dc31c4fd 100644 --- a/src/app/CASESessionManager.cpp +++ b/src/app/CASESessionManager.cpp @@ -125,9 +125,9 @@ OperationalDeviceProxy * CASESessionManager::FindSession(SessionHandle session) if (activeSession->MatchesSession(session)) { foundSession = activeSession; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundSession; @@ -140,9 +140,9 @@ OperationalDeviceProxy * CASESessionManager::FindExistingSession(NodeId id) if (activeSession->GetDeviceId() == id) { foundSession = activeSession; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundSession; diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 6ebd3707357494..6272e7235ad1ee 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -81,7 +81,7 @@ void InteractionModelEngine::Shutdown() // Increase magic number to invalidate all Handle-s. mMagic++; - mCommandHandlerObjs.ForEachActiveObject([this](CommandHandler * obj) -> bool { + mCommandHandlerObjs.ForEachActiveObject([this](CommandHandler * obj) -> Loop { // Modifying the pool during iteration is generally frowned upon. // This is almost safe since mCommandHandlerObjs is a BitMapObjectPool which won't malfunction when modifying the inner // record while during traversal. But this behavior is not guranteed, so we should fix this by implementing DeallocateAll. @@ -92,16 +92,16 @@ void InteractionModelEngine::Shutdown() // TODO(@kghost, #10332) Implement DeallocateAll and replace this. mCommandHandlerObjs.Deallocate(obj); - return true; + return Loop::Continue; }); - mTimedHandlers.ForEachActiveObject([this](TimedHandler * obj) -> bool { + mTimedHandlers.ForEachActiveObject([this](TimedHandler * obj) -> Loop { // This calls back into us and deallocates |obj|. As above, this is not // really guaranteed, and we should do something better here (like // ignoring the calls to OnTimedInteractionFailed and then doing a // DeallocateAll. mpExchangeMgr->CloseAllContextsForDelegate(obj); - return true; + return Loop::Continue; }); for (auto & readClient : mReadClients) diff --git a/src/channel/Manager.cpp b/src/channel/Manager.cpp index e821ce2071d2ef..8cba97bd83b405 100644 --- a/src/channel/Manager.cpp +++ b/src/channel/Manager.cpp @@ -29,9 +29,9 @@ ChannelHandle ChannelManager::EstablishChannel(const ChannelBuilder & builder, C if (context->MatchesBuilder(builder)) { channelContext = context; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); if (channelContext == nullptr) diff --git a/src/channel/Manager.h b/src/channel/Manager.h index 588fa099834292..d44e6df872d93a 100644 --- a/src/channel/Manager.h +++ b/src/channel/Manager.h @@ -57,7 +57,7 @@ class DLL_EXPORT ChannelManager : public SessionCreationDelegate mChannelHandles.ForEachActiveObject([&](ChannelContextHandleAssociation * association) { if (association->mChannelContext == channel) event(association->mChannelDelegate); - return true; + return Loop::Continue; }); } @@ -67,9 +67,9 @@ class DLL_EXPORT ChannelManager : public SessionCreationDelegate if (context->MatchesSession(session, mExchangeManager->GetSessionManager())) { context->OnNewConnection(session); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 72fe9e3987e52f..1157992b489109 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -708,9 +708,9 @@ CommissioneeDeviceProxy * DeviceCommissioner::FindCommissioneeDevice(SessionHand if (deviceProxy->MatchesSession(session)) { foundDevice = deviceProxy; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundDevice; @@ -723,9 +723,9 @@ CommissioneeDeviceProxy * DeviceCommissioner::FindCommissioneeDevice(NodeId id) if (deviceProxy->GetDeviceId() == id) { foundDevice = deviceProxy; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return foundDevice; diff --git a/src/inet/InetLayer.h b/src/inet/InetLayer.h index 8200ec060e8f21..a028a76eee979a 100644 --- a/src/inet/InetLayer.h +++ b/src/inet/InetLayer.h @@ -50,7 +50,7 @@ class EndPointManager { public: using EndPoint = EndPointType; - using EndPointVisitor = bool (*)(EndPoint *); + using EndPointVisitor = Loop (*)(EndPoint *); EndPointManager() {} virtual ~EndPointManager() {} @@ -83,7 +83,7 @@ class EndPointManager virtual EndPoint * CreateEndPoint() = 0; virtual void DeleteEndPoint(EndPoint * endPoint) = 0; - virtual bool ForEachEndPoint(const EndPointVisitor visitor) = 0; + virtual Loop ForEachEndPoint(const EndPointVisitor visitor) = 0; private: System::Layer * mSystemLayer; @@ -101,9 +101,9 @@ class EndPointManagerImplPool : public EndPointManager(endPoint)); } - bool ForEachEndPoint(const typename Manager::EndPointVisitor visitor) override + Loop ForEachEndPoint(const typename Manager::EndPointVisitor visitor) override { - return sEndPointPool.ForEachActiveObject([&](EndPoint * endPoint) -> bool { return visitor(endPoint); }); + return sEndPointPool.ForEachActiveObject([&](EndPoint * endPoint) -> Loop { return visitor(endPoint); }); } private: diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp index 1eb693ef833b4d..d5f2428a66c33b 100644 --- a/src/inet/TCPEndPoint.cpp +++ b/src/inet/TCPEndPoint.cpp @@ -2522,11 +2522,11 @@ void TCPEndPoint::HandleIdleTimer(chip::System::Layer * aSystemLayer, void * aAp auto & endPointManager = *reinterpret_cast *>(aAppState); bool lTimerRequired = IsIdleTimerRunning(endPointManager); - endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) -> bool { + endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) -> Loop { if (!lEndPoint->IsConnected()) - return true; + return Loop::Continue; if (lEndPoint->mIdleTimeout == 0) - return true; + return Loop::Continue; if (lEndPoint->mRemainingIdleTime == 0) { @@ -2537,7 +2537,7 @@ void TCPEndPoint::HandleIdleTimer(chip::System::Layer * aSystemLayer, void * aAp --lEndPoint->mRemainingIdleTime; } - return true; + return Loop::Continue; }); if (lTimerRequired) @@ -2550,7 +2550,9 @@ void TCPEndPoint::HandleIdleTimer(chip::System::Layer * aSystemLayer, void * aAp bool TCPEndPoint::IsIdleTimerRunning(EndPointManager & endPointManager) { // See if there are any TCP connections with the idle timer check in use. - return !endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) { return (lEndPoint->mIdleTimeout == 0); }); + return Loop::Break == endPointManager.ForEachEndPoint([](TCPEndPoint * lEndPoint) { + return (lEndPoint->mIdleTimeout == 0) ? Loop::Continue : Loop::Break; + }); } #endif // INET_TCP_IDLE_CHECK_INTERVAL > 0 diff --git a/src/lib/support/Pool.cpp b/src/lib/support/Pool.cpp index ddb574a3bec0e1..e1e64f3d3f8170 100644 --- a/src/lib/support/Pool.cpp +++ b/src/lib/support/Pool.cpp @@ -84,7 +84,8 @@ size_t StaticAllocatorBitmap::IndexOf(void * element) return index; } -bool StaticAllocatorBitmap::ForEachActiveObjectInner(void * context, bool lambda(void * context, void * object)) +using Lambda = Loop (*)(void *, void *); +Loop StaticAllocatorBitmap::ForEachActiveObjectInner(void * context, Lambda lambda) { for (size_t word = 0; word * kBitChunkSize < Capacity(); ++word) { @@ -94,12 +95,12 @@ bool StaticAllocatorBitmap::ForEachActiveObjectInner(void * context, bool lambda { if ((value & (kBit1 << offset)) != 0) { - if (!lambda(context, At(word * kBitChunkSize + offset))) - return false; + if (lambda(context, At(word * kBitChunkSize + offset)) == Loop::Break) + return Loop::Break; } } } - return true; + return Loop::Finish; } #if CHIP_SYSTEM_CONFIG_POOL_USE_HEAP @@ -116,20 +117,20 @@ HeapObjectListNode * HeapObjectList::FindNode(void * object) const return nullptr; } -using Lambda = bool (*)(void *, void *); -bool HeapObjectList::ForEachNode(void * context, bool lambda(void * context, void * object)) +using Lambda = Loop (*)(void *, void *); +Loop HeapObjectList::ForEachNode(void * context, Lambda lambda) { ++mIterationDepth; - bool result = true; + Loop result = Loop::Finish; bool anyReleased = false; HeapObjectListNode * p = mNext; while (p != this) { if (p->mObject != nullptr) { - if (!lambda(context, p->mObject)) + if (lambda(context, p->mObject) == Loop::Break) { - result = false; + result = Loop::Break; break; } } diff --git a/src/lib/support/Pool.h b/src/lib/support/Pool.h index ec9540756af73f..24605ea2425ace 100644 --- a/src/lib/support/Pool.h +++ b/src/lib/support/Pool.h @@ -32,6 +32,13 @@ namespace chip { +enum class Loop : uint8_t +{ + Continue, + Break, + Finish, +}; + namespace internal { class Statistics @@ -87,7 +94,7 @@ class StaticAllocatorBitmap : public internal::StaticAllocatorBase void * At(size_t index) { return static_cast(mElements) + mElementSize * index; } size_t IndexOf(void * element); - bool ForEachActiveObjectInner(void * context, bool lambda(void * context, void * object)); + Loop ForEachActiveObjectInner(void * context, Loop lambda(void * context, void * object)); private: void * mElements; @@ -112,7 +119,7 @@ class LambdaProxy { public: LambdaProxy(Function && function) : mFunction(std::move(function)) {} - static bool Call(void * context, void * target) + static Loop Call(void * context, void * target) { return static_cast(context)->mFunction(static_cast(target)); } @@ -150,7 +157,7 @@ struct HeapObjectList : HeapObjectListNode HeapObjectListNode * FindNode(void * object) const; - bool ForEachNode(void * context, bool lambda(void * context, void * object)); + Loop ForEachNode(void * context, Loop lambda(void * context, void * object)); size_t mIterationDepth; }; @@ -178,8 +185,8 @@ struct HeapObjectList : HeapObjectListNode * * @fn ForEachActiveObject * @memberof ObjectPool - * @param visitor A function that takes a T* and returns true to continue iterating or false to stop iterating. - * @returns false if a visitor call returned false, true otherwise. + * @param visitor A function that takes a T* and returns Loop::Continue to continue iterating or Loop::Break to stop iterating. + * @returns Loop::Break if a visitor call returned Loop::Break, Loop::Finish otherwise. * * Iteration may be nested. ReleaseObject() can be called during iteration, on the current object or any other. * CreateObject() can be called, but it is undefined whether or not a newly created object will be visited. @@ -226,25 +233,27 @@ class BitMapObjectPool : public internal::StaticAllocatorBitmap, public internal * @brief * Run a functor for each active object in the pool * - * @param function The functor of type `bool (*)(T*)`, return false to break the iteration - * @return bool Returns false if broke during iteration + * @param function The functor of type `Loop (*)(T*)`, return Loop::Break to break the iteration + * @return Loop Returns Break or Finish according to the iteration * * caution * this function is not thread-safe, make sure all usage of the * pool is protected by a lock, or else avoid using this function */ template - bool ForEachActiveObject(Function && function) + Loop ForEachActiveObject(Function && function) { + static_assert(std::is_same()))>::value, + "The function must take T* and return Loop"); internal::LambdaProxy proxy(std::forward(function)); return ForEachActiveObjectInner(&proxy, &internal::LambdaProxy::Call); } private: - static bool ReleaseObject(void * context, void * object) + static Loop ReleaseObject(void * context, void * object) { static_cast(context)->ReleaseObject(static_cast(object)); - return true; + return Loop::Continue; } std::atomic mUsage[(N + kBitChunkSize - 1) / kBitChunkSize]; @@ -314,22 +323,23 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon< * @brief * Run a functor for each active object in the pool * - * @param function The functor of type `bool (*)(T*)`, return false to break the iteration - * @return bool Returns false if broke during iteration + * @param function The functor of type `Loop (*)(T*)`, return Loop::Break to break the iteration + * @return Loop Returns Break or Finish according to the iteration */ template - bool ForEachActiveObject(Function && function) + Loop ForEachActiveObject(Function && function) { - // return ForEachNode([function](void *object) { return function(static_cast(object)); }); + static_assert(std::is_same()))>::value, + "The function must take T* and return Loop"); internal::LambdaProxy proxy(std::forward(function)); return mObjects.ForEachNode(&proxy, &internal::LambdaProxy::Call); } private: - static bool ReleaseObject(void * context, void * object) + static Loop ReleaseObject(void * context, void * object) { static_cast(context)->ReleaseObject(static_cast(object)); - return true; + return Loop::Continue; } internal::HeapObjectList mObjects; diff --git a/src/lib/support/PoolWrapper.h b/src/lib/support/PoolWrapper.h index 9bd3699ae769fc..2fe8e7d0ab285a 100644 --- a/src/lib/support/PoolWrapper.h +++ b/src/lib/support/PoolWrapper.h @@ -38,16 +38,18 @@ class PoolInterface virtual void ResetObject(U * element, ConstructorArguments &&... args) = 0; template - bool ForEachActiveObject(Function && function) + Loop ForEachActiveObject(Function && function) { - auto proxy = [&](U * target) -> bool { return function(target); }; + static_assert(std::is_same()))>::value, + "The function must take T* and return Loop"); + auto proxy = [&](U * target) -> Loop { return function(target); }; return ForEachActiveObjectInner( - &proxy, [](void * context, U * target) -> bool { return (*static_cast(context))(target); }); + &proxy, [](void * context, U * target) -> Loop { return (*static_cast(context))(target); }); } protected: - using Lambda = bool (*)(void *, U *); - virtual bool ForEachActiveObjectInner(void * context, Lambda lambda) = 0; + using Lambda = Loop (*)(void *, U *); + virtual Loop ForEachActiveObjectInner(void * context, Lambda lambda) = 0; }; template @@ -75,7 +77,7 @@ class PoolProxy> : public PoolInter } protected: - virtual bool ForEachActiveObjectInner(void * context, + virtual Loop ForEachActiveObjectInner(void * context, typename PoolInterface::Lambda lambda) override { return Impl().ForEachActiveObject([&](T * target) { return lambda(context, static_cast(target)); }); diff --git a/src/lib/support/tests/TestPool.cpp b/src/lib/support/tests/TestPool.cpp index 2245a9322baf9a..c9242d054cad1b 100644 --- a/src/lib/support/tests/TestPool.cpp +++ b/src/lib/support/tests/TestPool.cpp @@ -39,7 +39,7 @@ size_t GetNumObjectsInUse(POOL & pool) size_t count = 0; pool.ForEachActiveObject([&count](void *) { ++count; - return true; + return Loop::Continue; }); return count; } @@ -240,17 +240,17 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) objIds.erase(object->mId); ++count; sum += object->mId; - return true; + return Loop::Continue; }); NL_TEST_ASSERT(inSuite, count == kSize); NL_TEST_ASSERT(inSuite, sum == kSize * (kSize - 1) / 2); NL_TEST_ASSERT(inSuite, objIds.size() == 0); - // Verify that returning false stops iterating. + // Verify that returning Loop::Break stops iterating. count = 0; pool.ForEachActiveObject([&](S * object) { objIds.insert(object->mId); - return ++count != kSize / 2; + return ++count != kSize / 2 ? Loop::Continue : Loop::Break; }); NL_TEST_ASSERT(inSuite, count == kSize / 2); NL_TEST_ASSERT(inSuite, objIds.size() == kSize / 2); @@ -269,10 +269,10 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) { ++count; } - return true; + return Loop::Continue; }); } - return true; + return Loop::Continue; }); NL_TEST_ASSERT(inSuite, count == (kSize - 1) * kSize / 2); NL_TEST_ASSERT(inSuite, objIds.size() == 0); @@ -289,7 +289,7 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) { objIds.insert(object->mId); } - return true; + return Loop::Continue; }); NL_TEST_ASSERT(inSuite, count == kSize); NL_TEST_ASSERT(inSuite, objIds.size() == kSize / 2); @@ -316,7 +316,7 @@ void TestForEachActiveObject(nlTestSuite * inSuite, void * inContext) objArray[id] = pool.CreateObject(id); NL_TEST_ASSERT(inSuite, objArray[id] != nullptr); } - return true; + return Loop::Continue; }); for (size_t i = 0; i < kSize; ++i) { diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index eb3bc0a0d305f6..112821e9dfc796 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -101,7 +101,7 @@ CHIP_ERROR ExchangeManager::Shutdown() mContextPool.ForEachActiveObject([](auto * ec) { // There should be no active object in the pool VerifyOrDie(false); - return true; + return Loop::Continue; }); if (mSessionManager != nullptr) @@ -227,9 +227,9 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const // Matched ExchangeContext; send to message handler. ec->HandleMessage(packetHeader.GetMessageCounter(), payloadHeader, source, msgFlags, std::move(msgBuf)); found = true; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); if (found) @@ -323,7 +323,7 @@ void ExchangeManager::ExpireExchangesForSession(SessionHandle session) // Continue to iterate because there can be multiple exchanges // associated with the connection. } - return true; + return Loop::Continue; }); } @@ -339,7 +339,7 @@ void ExchangeManager::CloseAllContextsForDelegate(const ExchangeDelegate * deleg ec->SetDelegate(nullptr); ec->Close(); } - return true; + return Loop::Continue; }); } diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp index 675f9bda754ca1..81f0007a6611d4 100644 --- a/src/messaging/ReliableMessageMgr.cpp +++ b/src/messaging/ReliableMessageMgr.cpp @@ -67,7 +67,7 @@ void ReliableMessageMgr::Shutdown() // Clear the retransmit table mRetransTable.ForEachActiveObject([&](auto * entry) { mRetransTable.ReleaseObject(entry); - return true; + return Loop::Continue; }); mSystemLayer = nullptr; @@ -83,7 +83,7 @@ void ReliableMessageMgr::TicklessDebugDumpRetransTable(const char * log) "EC:" ChipLogFormatExchange " MessageCounter:" ChipLogFormatMessageCounter " NextRetransTimeCtr:%" PRIu64, ChipLogValueExchange(&entry->ec.Get()), entry->retainedBuf.GetMessageCounter(), entry->nextRetransTime.count()); - return true; + return Loop::Continue; }); } #else @@ -117,7 +117,7 @@ void ReliableMessageMgr::ExecuteActions() // Retransmit / cancel anything in the retrans table whose retrans timeout has expired mRetransTable.ForEachActiveObject([&](auto * entry) { if (entry->nextRetransTime > now) - return true; + return Loop::Continue; VerifyOrDie(!entry->retainedBuf.IsNull()); @@ -133,7 +133,7 @@ void ReliableMessageMgr::ExecuteActions() // Do not StartTimer, we will schedule the timer at the end of the timer handler. mRetransTable.ReleaseObject(entry); - return true; + return Loop::Continue; } ChipLogDetail(ExchangeManager, @@ -145,7 +145,7 @@ void ReliableMessageMgr::ExecuteActions() SendFromRetransTable(entry); // For test not using async IO loop, the entry may have been removed after send, do not use entry below - return true; + return Loop::Continue; }); TicklessDebugDumpRetransTable("ReliableMessageMgr::ExecuteActions Dumping mRetransTable entries after processing"); @@ -203,9 +203,9 @@ bool ReliableMessageMgr::CheckAndRemRetransTable(ReliableMessageContext * rc, ui " from Retrans Table on exchange " ChipLogFormatExchange, ackMessageCounter, ChipLogValueExchange(rc->GetExchangeContext())); removed = true; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return removed; @@ -265,9 +265,9 @@ void ReliableMessageMgr::ClearRetransTable(ReliableMessageContext * rc) if (entry->ec->GetReliableMessageContext() == rc) { ClearRetransTable(*entry); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -296,7 +296,7 @@ void ReliableMessageMgr::StartTimer() { nextWakeTime = entry->nextRetransTime; } - return true; + return Loop::Continue; }); if (nextWakeTime != System::Clock::Timestamp::max()) @@ -330,7 +330,7 @@ int ReliableMessageMgr::TestGetCountRetransTable() int count = 0; mRetransTable.ForEachActiveObject([&](auto * entry) { count++; - return true; + return Loop::Continue; }); return count; } diff --git a/src/messaging/ReliableMessageMgr.h b/src/messaging/ReliableMessageMgr.h index b1326b9b95747f..8d6034ec825a0b 100644 --- a/src/messaging/ReliableMessageMgr.h +++ b/src/messaging/ReliableMessageMgr.h @@ -177,7 +177,7 @@ class ReliableMessageMgr { mContextPool.ForEachActiveObject([&](auto * ec) { function(ec->GetReliableMessageContext()); - return true; + return Loop::Continue; }); } diff --git a/src/transport/SecureSessionTable.h b/src/transport/SecureSessionTable.h index 62a2429e172a5f..d40e6626b6789a 100644 --- a/src/transport/SecureSessionTable.h +++ b/src/transport/SecureSessionTable.h @@ -69,7 +69,7 @@ class SecureSessionTable void ReleaseSession(SecureSession * session) { mEntries.ReleaseObject(session); } template - bool ForEachSession(Function && function) + Loop ForEachSession(Function && function) { return mEntries.ForEachActiveObject(std::forward(function)); } @@ -89,9 +89,9 @@ class SecureSessionTable if (session->GetLocalSessionId() == localSessionId) { result = session; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return result; } @@ -115,7 +115,7 @@ class SecureSessionTable callback(*session); ReleaseSession(session); } - return true; + return Loop::Continue; }); } diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index e2f4ac7d843f1e..87be4943ed0369 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -261,7 +261,7 @@ void SessionManager::ExpireAllPairings(NodeId peerNodeId, FabricIndex fabric) HandleConnectionExpired(*session); mSecureSessions.ReleaseSession(session); } - return true; + return Loop::Continue; }); } @@ -274,7 +274,7 @@ void SessionManager::ExpireAllPairingsForFabric(FabricIndex fabric) HandleConnectionExpired(*session); mSecureSessions.ReleaseSession(session); } - return true; + return Loop::Continue; }); } @@ -319,7 +319,7 @@ CHIP_ERROR SessionManager::NewPairing(const Optional & p SessionHandle sessionHandle(session->GetPeerNodeId(), session->GetLocalSessionId(), session->GetPeerSessionId(), fabric); mSessionCreationDelegates.ForEachActiveObject([&](std::reference_wrapper * cb) { cb->get().OnNewSession(sessionHandle); - return true; + return Loop::Continue; }); return CHIP_NO_ERROR; @@ -369,7 +369,7 @@ void SessionManager::RegisterRecoveryDelegate(SessionRecoveryDelegate & cb) #ifndef NDEBUG mSessionRecoveryDelegates.ForEachActiveObject([&](std::reference_wrapper * i) { VerifyOrDie(std::addressof(cb) != std::addressof(i->get())); - return true; + return Loop::Continue; }); #endif std::reference_wrapper * slot = mSessionRecoveryDelegates.CreateObject(cb); @@ -382,9 +382,9 @@ void SessionManager::UnregisterRecoveryDelegate(SessionRecoveryDelegate & cb) if (std::addressof(cb) == std::addressof(i->get())) { mSessionRecoveryDelegates.ReleaseObject(i); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -392,7 +392,7 @@ void SessionManager::RefreshSessionOperationalData(const SessionHandle & session { mSessionRecoveryDelegates.ForEachActiveObject([&](std::reference_wrapper * cb) { cb->get().OnFirstMessageDeliveryFailed(sessionHandle); - return true; + return Loop::Continue; }); } @@ -595,7 +595,7 @@ void SessionManager::HandleConnectionExpired(const Transport::SecureSession & se session.GetFabricIndex()); mSessionReleaseDelegates.ForEachActiveObject([&](std::reference_wrapper * cb) { cb->get().OnSessionReleased(sessionHandle); - return true; + return Loop::Continue; }); mTransportMgr->Disconnect(session.GetPeerAddress()); @@ -632,9 +632,9 @@ SessionHandle SessionManager::FindSecureSessionForNode(NodeId peerNodeId) if (session->GetPeerNodeId() == peerNodeId) { found = session; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); VerifyOrDie(found != nullptr); diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index 3cd472ff49f6be..6e8ec58a7fbd7e 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -154,7 +154,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate #ifndef NDEBUG mSessionCreationDelegates.ForEachActiveObject([&](std::reference_wrapper * i) { VerifyOrDie(std::addressof(cb) != std::addressof(i->get())); - return true; + return Loop::Continue; }); #endif std::reference_wrapper * slot = mSessionCreationDelegates.CreateObject(cb); @@ -167,9 +167,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate if (std::addressof(cb) == std::addressof(i->get())) { mSessionCreationDelegates.ReleaseObject(i); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } @@ -179,7 +179,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate #ifndef NDEBUG mSessionReleaseDelegates.ForEachActiveObject([&](std::reference_wrapper * i) { VerifyOrDie(std::addressof(cb) != std::addressof(i->get())); - return true; + return Loop::Continue; }); #endif std::reference_wrapper * slot = mSessionReleaseDelegates.CreateObject(cb); @@ -192,9 +192,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate if (std::addressof(cb) == std::addressof(i->get())) { mSessionReleaseDelegates.ReleaseObject(i); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); } diff --git a/src/transport/UnauthenticatedSessionTable.h b/src/transport/UnauthenticatedSessionTable.h index c265d43fe249e7..032f19e2a919f1 100644 --- a/src/transport/UnauthenticatedSessionTable.h +++ b/src/transport/UnauthenticatedSessionTable.h @@ -159,9 +159,9 @@ class UnauthenticatedSessionTable if (MatchPeerAddress(entry->GetPeerAddress(), address)) { result = entry; - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); return result; } @@ -177,7 +177,7 @@ class UnauthenticatedSessionTable result = entry; oldestTime = entry->GetLastActivityTime(); } - return true; + return Loop::Continue; }); return result; diff --git a/src/transport/raw/TCP.cpp b/src/transport/raw/TCP.cpp index 82b8a7c0274197..d8db200488d718 100644 --- a/src/transport/raw/TCP.cpp +++ b/src/transport/raw/TCP.cpp @@ -213,9 +213,9 @@ CHIP_ERROR TCPBase::SendAfterConnect(const PeerAddress & addr, System::PacketBuf // same destination exists. alreadyConnecting = true; pending->mPacketBuffer->AddToEnd(std::move(msg)); - return false; + return Loop::Break; } - return true; + return Loop::Continue; }); // If already connecting, buffer was just enqueued for more sending @@ -378,7 +378,7 @@ void TCPBase::OnConnectionComplete(Inet::TCPEndPoint * endPoint, CHIP_ERROR inet err = endPoint->Send(std::move(buffer)); } } - return true; + return Loop::Continue; }); if (err == CHIP_NO_ERROR)