Skip to content

Commit

Permalink
Check max message big enough for registering transport
Browse files Browse the repository at this point in the history
Signed-off-by: Eugenio Collado <[email protected]>
  • Loading branch information
EugenioCollado committed Dec 23, 2024
1 parent 9fdbe1a commit c302b22
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,25 @@ static bool get_unique_flows_parameters(
return true;
}

/**
* @brief This method checks if the maximum message size is equal or higher than the PDP package size.
* @return true if the maximum message size is equal or higher than the PDP package size, false otherwise.
*/
static bool is_max_message_size_big_enough(
const uint32_t max_message_size)
{
constexpr uint32_t info_dst_message_length = 16;
constexpr uint32_t info_ts_message_length = 12;
uint32_t statistics_message_length = 0;
#ifdef FASTDDS_STATISTICS
statistics_message_length = eprosima::fastdds::statistics::rtps::statistics_submessage_length;
#endif // FASTDDS_STATISTICS

return max_message_size >=
(RTPSMESSAGE_HEADER_SIZE + BUILTIN_DATA_MAX_SIZE + info_dst_message_length +
info_ts_message_length + statistics_message_length);
}

Locator_t& RTPSParticipantImpl::applyLocatorAdaptRule(
Locator_t& loc)
{
Expand Down Expand Up @@ -480,6 +499,14 @@ bool RTPSParticipantImpl::setup_transports()
register_transport = false;
}
}
auto max_message_size = transportDescriptor->max_message_size();
if (!is_max_message_size_big_enough(max_message_size))
{
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT,
"User transport failed to register. Maximum message size needs to be equal or higher than "
"the PDP package size.");
register_transport = false;
}

bool transport_registered = register_transport && m_network_Factory.RegisterTransport(
transportDescriptor.get(), &m_att.properties, m_att.max_msg_size_no_frag);
Expand All @@ -495,12 +522,12 @@ bool RTPSParticipantImpl::setup_transports()
if (transport_registered)
{
has_shm_transport_ |=
(dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr);
(nullptr != dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get()));
}
else
{
// SHM transport could be disabled
if ((dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get()) != nullptr))
if ((nullptr != dynamic_cast<SharedMemTransportDescriptor*>(transportDescriptor.get())))
{
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT,
"Unable to Register SHM Transport. SHM Transport is not supported in"
Expand Down

0 comments on commit c302b22

Please sign in to comment.