From b637b4d64ddf3cdf5df108b9fcca2ebdfde82277 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 26 Apr 2023 10:24:17 +0200 Subject: [PATCH] Cancel timer before stopping event loop --- src/platform/tests/TestDnssd.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/platform/tests/TestDnssd.cpp b/src/platform/tests/TestDnssd.cpp index a72b1b34dbce8d..d0e6a3cc3233b8 100644 --- a/src/platform/tests/TestDnssd.cpp +++ b/src/platform/tests/TestDnssd.cpp @@ -52,6 +52,14 @@ struct DnssdContext } // namespace +static void Timeout(chip::System::Layer * systemLayer, void * context) +{ + auto * ctx = static_cast(context); + ChipLogError(DeviceLayer, "mDNS test timeout, is avahi daemon running?"); + ctx->mTimeoutExpired = true; + chip::DeviceLayer::PlatformMgr().StopEventLoopTask(); +} + static void HandleResolve(void * context, DnssdService * result, const chip::Span & addresses, CHIP_ERROR error) { @@ -74,6 +82,7 @@ static void HandleResolve(void * context, DnssdService * result, const chip::Spa if (ctx->mBrowsedServicesCount == ++ctx->mResolvedServicesCount) { + chip::DeviceLayer::SystemLayer().CancelTimer(Timeout, context); // After last service is resolved, stop the event loop, // so the test case can gracefully exit. chip::DeviceLayer::PlatformMgr().StopEventLoopTask(); @@ -106,14 +115,6 @@ static void HandleBrowse(void * context, DnssdService * services, size_t service } } -static void Timeout(chip::System::Layer * systemLayer, void * context) -{ - auto * ctx = static_cast(context); - ChipLogError(DeviceLayer, "mDNS test timeout, is avahi daemon running?"); - ctx->mTimeoutExpired = true; - chip::DeviceLayer::PlatformMgr().StopEventLoopTask(); -} - static void DnssdErrorCallback(void * context, CHIP_ERROR error) { auto * ctx = static_cast(context);