Skip to content

Commit

Permalink
host: Remove duplicates in uhd::device::find result
Browse files Browse the repository at this point in the history
When find issues a broadcast to identify devices in the network
it might happen that it receives multiple answers from the same
device due to network topology.

This fix removes these duplicates by utilizing the hash method
of device.cpp.

This fixes EttusResearch#729.
  • Loading branch information
NI-LAm authored and joergho committed Oct 24, 2024
1 parent fed089e commit f0638ee
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions host/lib/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <future>
#include <memory>
#include <mutex>
#include <set>
#include <tuple>

using namespace uhd;
Expand Down Expand Up @@ -101,6 +102,19 @@ device_addrs_t device::find(const device_addr_t& hint, device_filter_t filter)
}
}

// find might return duplicate entries if a device received a broadcast multiple
// times. These entries needs to be removed from the result.
std::set<size_t> device_hashes;
device_addrs.erase(std::remove_if(device_addrs.begin(),
device_addrs.end(),
[&device_hashes](const device_addr_t& other) {
size_t hash = hash_device_addr(other);
const bool result = device_hashes.count(hash);
device_hashes.insert(hash);
return result;
}),
device_addrs.end());

return device_addrs;
}

Expand Down

0 comments on commit f0638ee

Please sign in to comment.