Skip to content

Commit

Permalink
Cancel timer before stopping event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Apr 26, 2023
1 parent 51a3a51 commit b637b4d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/platform/tests/TestDnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ struct DnssdContext

} // namespace

static void Timeout(chip::System::Layer * systemLayer, void * context)
{
auto * ctx = static_cast<DnssdContext *>(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<chip::Inet::IPAddress> & addresses,
CHIP_ERROR error)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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<DnssdContext *>(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<DnssdContext *>(context);
Expand Down

0 comments on commit b637b4d

Please sign in to comment.