Skip to content

Commit

Permalink
Refs #22519. Reuse unique ports for locators of same kind in a reader
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <[email protected]>
  • Loading branch information
juanlofer-eprosima committed Jan 21, 2025
1 parent 4a15f6a commit 67058bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <algorithm>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <sstream>
Expand Down Expand Up @@ -1732,10 +1733,15 @@ bool RTPSParticipantImpl::createAndAssociateReceiverswithEndpoint(
attributes.external_unicast_locators.clear();

// Create unique flows for unicast locators
std::map<int32_t, int16_t> created_resources; // Register created resources to distinguish the case where
// a receiver was created in this same function call (and can be
// reused for other locators of the same kind in this reader),
// and that in which it was already created before for other reader
// in this same participant.
LocatorList_t input_locator_list = m_att.defaultUnicastLocatorList;
for (Locator_t& loc : input_locator_list)
{
uint16_t port = initial_unique_port;
uint16_t port = created_resources.count(loc.kind) ? created_resources[loc.kind] : initial_unique_port;
while (port < final_unique_port)
{
// Set logical port only TCP locators
Expand All @@ -1751,15 +1757,18 @@ bool RTPSParticipantImpl::createAndAssociateReceiverswithEndpoint(
loc.port = port;
}

// Try creating receiver for this locator
// Try creating receiver for this locator
LocatorList_t aux_locator_list;
aux_locator_list.push_back(loc);
// if (createReceiverResources(aux_locator_list, false, true, false))
// {
// break;
// }
createReceiverResources(aux_locator_list, false, true, false);
if (!aux_locator_list.empty())
if (createReceiverResources(aux_locator_list, false, true, false))
{
created_resources[loc.kind] = port;
}

// Locator will be present in the list if receiver was created, or was already created
// Continue if receiver not created for this reader (might exist but created for other reader in this same participant)
if (!aux_locator_list.empty() &&
created_resources.count(loc.kind) && (created_resources[loc.kind] == port))
{
break;
}
Expand Down Expand Up @@ -1893,7 +1902,7 @@ bool RTPSParticipantImpl::createReceiverResources(
bool ret_val = input_list.empty();

#if HAVE_SECURITY
// An auxilary buffer is needed in the ReceiverResource to to decrypt the message,
// An auxilary buffer is needed in the ReceiverResource to decrypt the message,
// that imposes a limit in the received messages size even if the transport allows (uint32_t) messages size.
uint32_t max_receiver_buffer_size =
is_secure() ? std::numeric_limits<uint16_t>::max() : (std::numeric_limits<uint32_t>::max)();
Expand Down
1 change: 1 addition & 0 deletions src/cpp/rtps/participant/RTPSParticipantImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ class RTPSParticipantImpl
* @param ApplyMutation - True if we want to create a Resource with a "similar" locator if the one we provide is unavailable
* @param RegisterReceiver - True if we want the receiver to be registered. Useful for receivers created after participant is enabled.
* @param log_when_creation_fails - True if a log warning shall be issued for each locator when a receiver resource cannot be created.
* @return True if a receiver resource was created for at least a locator in the list, false otherwise.
*/
bool createReceiverResources(
LocatorList_t& Locator_list,
Expand Down

0 comments on commit 67058bd

Please sign in to comment.