Skip to content

Commit

Permalink
Darwin: Avoid calling DnssdServer::StartServer() when not initialized (
Browse files Browse the repository at this point in the history
…#34465)

* Darwin: Avoid calling DnssdServer::StartServer() when not initialized

Look at the SystemState directly instead of relying on _controllers.

* Return error from AdvertiseOperational when fabric table is null
  • Loading branch information
ksperling-apple authored Jul 24, 2024
1 parent 138fb4f commit 8306353
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/server/Dnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void DnssdServer::GetPrimaryOrFallbackMACAddress(chip::MutableByteSpan mac)
/// Set MDNS operational advertisement
CHIP_ERROR DnssdServer::AdvertiseOperational()
{
VerifyOrDie(mFabricTable != nullptr);
VerifyOrReturnError(mFabricTable != nullptr, CHIP_ERROR_INCORRECT_STATE);

for (const FabricInfo & fabricInfo : *mFabricTable)
{
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceControllerSystemState.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class DeviceControllerSystemState
mGroupDataProvider != nullptr && mReportScheduler != nullptr && mTimerDelegate != nullptr &&
mSessionKeystore != nullptr && mSessionResumptionStorage != nullptr && mBDXTransferServer != nullptr;
};
bool IsShutDown() { return mHaveShutDown; }
bool IsShutDown() const { return mHaveShutDown; }

System::Layer * SystemLayer() const { return mSystemLayer; };
Inet::EndPointManager<Inet::TCPEndPoint> * TCPEndPointManager() const { return mTCPEndPointManager; };
Expand Down
9 changes: 4 additions & 5 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,10 @@ - (void)resetOperationalAdvertising
// If we're not advertising, then there's no need to reset anything.
VerifyOrReturn(_advertiseOperational);

// If there are no running controllers there will be no advertisements to reset.
{
std::lock_guard lock(_controllersLock);
VerifyOrReturn(_controllers.count > 0);
}
// Ensure the stack is running. We can't look at _controllers to determine this
// reliably because it gets updated early during controller startup from off-queue.
auto systemState = _controllerFactory->GetSystemState();
VerifyOrReturn(systemState != nullptr && !systemState->IsShutDown());

// StartServer() is the only API we have for resetting DNS-SD advertising.
// It sure would be nice if there were a "restart" that was a no-op if the
Expand Down

0 comments on commit 8306353

Please sign in to comment.