|
13 | 13 | using namespace lsl; |
14 | 14 |
|
15 | 15 | resolve_attempt_udp::resolve_attempt_udp(asio::io_context &io, const udp &protocol, |
16 | | - const std::vector<udp::endpoint> &targets, const std::string &query, result_container &results, |
17 | | - std::mutex &results_mut, double cancel_after, cancellable_registry *registry) |
18 | | - : io_(io), results_(results), results_mut_(results_mut), cancel_after_(cancel_after), |
19 | | - cancelled_(false), targets_(targets), query_(query), unicast_socket_(io), |
20 | | - broadcast_socket_(io), multicast_socket_(io), recv_socket_(io), cancel_timer_(io) { |
| 16 | + const std::vector<udp::endpoint> &targets, const std::string &query, resolver_impl &resolver, |
| 17 | + double cancel_after) |
| 18 | + : io_(io), resolver_(resolver), cancel_after_(cancel_after), cancelled_(false), |
| 19 | + targets_(targets), query_(query), unicast_socket_(io), broadcast_socket_(io), |
| 20 | + multicast_socket_(io), recv_socket_(io), cancel_timer_(io) { |
21 | 21 | // open the sockets that we might need |
22 | 22 | recv_socket_.open(protocol); |
23 | 23 | try { |
@@ -57,7 +57,7 @@ resolve_attempt_udp::resolve_attempt_udp(asio::io_context &io, const udp &protoc |
57 | 57 | query_msg_.c_str()); |
58 | 58 |
|
59 | 59 | // register ourselves as a candidate for cancellation |
60 | | - if (registry) register_at(registry); |
| 60 | + register_at(&resolver); |
61 | 61 | } |
62 | 62 |
|
63 | 63 | resolve_attempt_udp::~resolve_attempt_udp() { |
@@ -116,20 +116,24 @@ void resolve_attempt_udp::handle_receive_outcome(err_t err, std::size_t len) { |
116 | 116 | std::string uid = info.uid(); |
117 | 117 | { |
118 | 118 | // update the results |
119 | | - std::lock_guard<std::mutex> lock(results_mut_); |
120 | | - if (results_.find(uid) == results_.end()) |
121 | | - results_[uid] = std::make_pair(info, lsl_clock()); // insert new result |
| 119 | + std::lock_guard<std::mutex> lock(resolver_.results_mut_); |
| 120 | + auto it = resolver_.results_.find(uid); |
| 121 | + if (it == resolver_.results_.end()) |
| 122 | + // insert new result, store iterator in it |
| 123 | + it = resolver_.results_.emplace(uid, std::make_pair(info, lsl_clock())) |
| 124 | + .first; |
122 | 125 | else |
123 | | - results_[uid].second = lsl_clock(); // update only the receive time |
| 126 | + it->second.second = lsl_clock(); // update only the receive time |
| 127 | + auto &stored_info = it->second.first; |
124 | 128 | // ... also update the address associated with the result (but don't |
125 | 129 | // override the address of an earlier record for this stream since this |
126 | 130 | // would be the faster route) |
127 | 131 | if (remote_endpoint_.address().is_v4()) { |
128 | | - if (results_[uid].first.v4address().empty()) |
129 | | - results_[uid].first.v4address(remote_endpoint_.address().to_string()); |
| 132 | + if (stored_info.v4address().empty()) |
| 133 | + stored_info.v4address(remote_endpoint_.address().to_string()); |
130 | 134 | } else { |
131 | | - if (results_[uid].first.v6address().empty()) |
132 | | - results_[uid].first.v6address(remote_endpoint_.address().to_string()); |
| 135 | + if (stored_info.v6address().empty()) |
| 136 | + stored_info.v6address(remote_endpoint_.address().to_string()); |
133 | 137 | } |
134 | 138 | } |
135 | 139 | } |
|
0 commit comments