diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index c77c00fd1e..b99d74753e 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -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) { @@ -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); @@ -495,12 +522,12 @@ bool RTPSParticipantImpl::setup_transports() if (transport_registered) { has_shm_transport_ |= - (dynamic_cast(transportDescriptor.get()) != nullptr); + (nullptr != dynamic_cast(transportDescriptor.get())); } else { // SHM transport could be disabled - if ((dynamic_cast(transportDescriptor.get()) != nullptr)) + if ((nullptr != dynamic_cast(transportDescriptor.get()))) { EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "Unable to Register SHM Transport. SHM Transport is not supported in"