Skip to content

Commit b183f88

Browse files
authored
fix getConnections (#285)
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
1 parent a52146d commit b183f88

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/network/impl/connection_manager_impl.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ namespace libp2p::network {
2323
if (it == connections_.end()) {
2424
return {};
2525
}
26-
27-
return std::vector<ConnectionManager::ConnectionSPtr>(it->second.begin(),
28-
it->second.end());
26+
std::vector<ConnectionSPtr> out;
27+
out.reserve(it->second.size());
28+
for (const auto &conn : it->second) {
29+
if (not conn->isClosed()) {
30+
out.emplace_back(conn);
31+
}
32+
}
33+
return out;
2934
}
3035

3136
ConnectionManager::ConnectionSPtr
@@ -66,7 +71,11 @@ namespace libp2p::network {
6671
out.reserve(connections_.size());
6772

6873
for (auto &&entry : connections_) {
69-
out.insert(out.end(), entry.second.begin(), entry.second.end());
74+
for (const auto &conn : entry.second) {
75+
if (not conn->isClosed()) {
76+
out.emplace_back(conn);
77+
}
78+
}
7079
}
7180

7281
return out;

0 commit comments

Comments
 (0)