Skip to content

Commit

Permalink
Refs #22056: Review - Use map::insert and std::set in test
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <carlosferreira@eprosima.com>
  • Loading branch information
cferreiragonz committed Nov 14, 2024
1 parent 039962e commit 6b99a05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/cpp/rtps/transport/TCPTransportInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,9 @@ ResponseCode TCPTransportInterface::bind_socket(
unbound_channel_resources_.erase(it_remove);

ResponseCode ret = RETCODE_OK;
if (channel_resources_.find(channel->locator()) == channel_resources_.end())
{
channel_resources_[channel->locator()] = channel;
}
else
const auto insert_ret = channel_resources_.insert(
decltype(channel_resources_)::value_type{channel->locator(), channel});
if (false == insert_ret.second)
{
// There is an existing channel that can be used. Force the Client to close unnecessary socket
ret = RETCODE_SERVER_ERROR;
Expand All @@ -322,10 +320,7 @@ ResponseCode TCPTransportInterface::bind_socket(
for (auto& interface_it : local_interfaces)
{
IPLocator::setIPv4(local_locator, interface_it.locator);
if (channel_resources_.find(local_locator) == channel_resources_.end())
{
channel_resources_[local_locator] = channel;
}
channel_resources_.insert(decltype(channel_resources_)::value_type{local_locator, channel});
}
}
return ret;
Expand Down
7 changes: 6 additions & 1 deletion test/unittest/transport/TCPv4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,12 @@ TEST_F(TCPv4Tests, client_announced_local_port_uniqueness)

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

ASSERT_GT(receiveTransportUnderTest.get_channel_resources().size(), 2u);
std::set<std::shared_ptr<TCPChannelResource>> channels_created;
for (const auto& channel_resource : receiveTransportUnderTest.get_channel_resources())
{
channels_created.insert(channel_resource.second);
}
ASSERT_EQ(channels_created.size(), 2u);
}

#ifndef _WIN32
Expand Down

0 comments on commit 6b99a05

Please sign in to comment.