Skip to content

Commit

Permalink
Change mdns broadcast to allow treatement as success if sends (#7555)
Browse files Browse the repository at this point in the history
* Change mdns broadcast to allow treatement as success if anything succeeds

* Fix typo

* Add progress log for mdns broadcast success
  • Loading branch information
andy31415 authored and pull[bot] committed Jul 13, 2021
1 parent 0bde314 commit 2352552
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/lib/mdns/minimal/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ CHIP_ERROR ServerBase::BroadcastSend(chip::System::PacketBufferHandle && data, u

CHIP_ERROR ServerBase::BroadcastSend(chip::System::PacketBufferHandle && data, uint16_t port)
{
// Broadcast requires sending data multiple times, each of which may error
// out, yet broadcast only has a single error code.
//
// The general logic of error handling is:
// - if no send done at all, return error
// - if at least one broadcast succeeds, assume success overall
// + some internal consistency validations for state error.

bool hadSuccesfulSend = false;
CHIP_ERROR lastError = CHIP_ERROR_NO_ENDPOINT;

for (size_t i = 0; i < mEndpointCount; i++)
{
EndpointInfo * info = &mEndpoints[i];
Expand Down Expand Up @@ -291,22 +302,28 @@ CHIP_ERROR ServerBase::BroadcastSend(chip::System::PacketBufferHandle && data, u
#endif
else
{
// This is a general error of internal consistency: every address has a known type
// Fail completely otherwise.
return CHIP_ERROR_INCORRECT_STATE;
}

if (err == chip::System::MapErrorPOSIX(ENETUNREACH))
if (err == CHIP_NO_ERROR)
{
// Send attempted to an unreachable network. Generally should not happen if
// interfaces are configured properly, however such a failure to broadcast
// may not be critical either.
ChipLogError(Discovery, "Attempt to mDNS broadcast to an unreachable destination.");
hadSuccesfulSend = true;
ChipLogProgress(Discovery, "mDNS broadcast success");
}
else if (err != CHIP_NO_ERROR)
else
{
return err;
ChipLogError(Discovery, "Attempt to mDNS broadcast failed: %s", chip::ErrorStr(err));
lastError = err;
}
}

if (!hadSuccesfulSend)
{
return lastError;
}

return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 2352552

Please sign in to comment.