Skip to content

Commit 6b99a05

Browse files
committed
Refs #22056: Review - Use map::insert and std::set in test
Signed-off-by: cferreiragonz <[email protected]>
1 parent 039962e commit 6b99a05

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/cpp/rtps/transport/TCPTransportInterface.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,9 @@ ResponseCode TCPTransportInterface::bind_socket(
303303
unbound_channel_resources_.erase(it_remove);
304304

305305
ResponseCode ret = RETCODE_OK;
306-
if (channel_resources_.find(channel->locator()) == channel_resources_.end())
307-
{
308-
channel_resources_[channel->locator()] = channel;
309-
}
310-
else
306+
const auto insert_ret = channel_resources_.insert(
307+
decltype(channel_resources_)::value_type{channel->locator(), channel});
308+
if (false == insert_ret.second)
311309
{
312310
// There is an existing channel that can be used. Force the Client to close unnecessary socket
313311
ret = RETCODE_SERVER_ERROR;
@@ -322,10 +320,7 @@ ResponseCode TCPTransportInterface::bind_socket(
322320
for (auto& interface_it : local_interfaces)
323321
{
324322
IPLocator::setIPv4(local_locator, interface_it.locator);
325-
if (channel_resources_.find(local_locator) == channel_resources_.end())
326-
{
327-
channel_resources_[local_locator] = channel;
328-
}
323+
channel_resources_.insert(decltype(channel_resources_)::value_type{local_locator, channel});
329324
}
330325
}
331326
return ret;

test/unittest/transport/TCPv4Tests.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,12 @@ TEST_F(TCPv4Tests, client_announced_local_port_uniqueness)
20352035

20362036
std::this_thread::sleep_for(std::chrono::milliseconds(100));
20372037

2038-
ASSERT_GT(receiveTransportUnderTest.get_channel_resources().size(), 2u);
2038+
std::set<std::shared_ptr<TCPChannelResource>> channels_created;
2039+
for (const auto& channel_resource : receiveTransportUnderTest.get_channel_resources())
2040+
{
2041+
channels_created.insert(channel_resource.second);
2042+
}
2043+
ASSERT_EQ(channels_created.size(), 2u);
20392044
}
20402045

20412046
#ifndef _WIN32

0 commit comments

Comments
 (0)