Skip to content

Commit

Permalink
Refs #12601: performance, only calculate key if handle is NIL. Standa…
Browse files Browse the repository at this point in the history
…rd compliance

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
  • Loading branch information
JLBuenoLopez committed Sep 30, 2021
1 parent 48f16a5 commit 8a79678
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions include/fastdds/dds/publisher/DataWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,9 @@ class DataWriter : public DomainEntity
* @param max_wait Maximum blocking time for this operation.
*
* @return RETCODE_NOT_ENABLED if the writer has not been enabled.
* @return RETCODE_BAD_PARAMETER if `instance` is not a valid pointer or the key is not consistent with `handle`.
* @return RETCODE_PRECONDITION_NOT_MET if the topic does not have a key or the key is unkown to the writer.
* @return RETCODE_BAD_PARAMETER if `instance` is not a valid pointer.
* @return RETCODE_PRECONDITION_NOT_MET if the topic does not have a key, the key is unknown to the writer,
* or the key is not consistent with `handle`.
* @return RETCODE_OK if the DataWriter receive the acknowledgments before the time expires.
* @return RETCODE_ERROR otherwise.
*/
Expand Down
15 changes: 10 additions & 5 deletions src/cpp/fastdds/publisher/DataWriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,19 +1017,24 @@ ReturnCode_t DataWriterImpl::wait_for_acknowledgments(
return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET;
}

InstanceHandle_t ih = c_InstanceHandle_Unknown;
InstanceHandle_t ih = handle;

bool is_key_protected = false;
#if defined(NDEBUG)
if (c_InstanceHandle_Unknown == ih)
#endif // NDEBUG
{
bool is_key_protected = false;
#if HAVE_SECURITY
is_key_protected = writer_->getAttributes().security_attributes().is_key_protected;
is_key_protected = writer_->getAttributes().security_attributes().is_key_protected;
#endif // HAVE_SECURITY
type_->getKey(instance, &ih, is_key_protected);
type_->getKey(instance, &ih, is_key_protected);
}

#if !defined(NDEBUG)
if (c_InstanceHandle_Unknown != handle && ih != handle)
{
logError(PUBLISHER, "handle differs from data's key");
return ReturnCode_t::RETCODE_BAD_PARAMETER;
return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET;
}
#endif // NDEBUG */

Expand Down
4 changes: 3 additions & 1 deletion test/unittest/dds/publisher/DataWriterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,11 @@ TEST(DataWriterTests, InstanceWaitForAcknowledgement)
EXPECT_EQ(ReturnCode_t::RETCODE_BAD_PARAMETER, instance_datawriter->wait_for_acknowledgments(nullptr, handle,
max_wait));

#if !defined(NDEBUG)
// 4. Calling wait_for_acknowledgments with an inconsistent handle returns RETCODE_BAD_PARAMETER
EXPECT_EQ(ReturnCode_t::RETCODE_BAD_PARAMETER, instance_datawriter->wait_for_acknowledgments(&data,
EXPECT_EQ(ReturnCode_t::RETCODE_PRECONDITION_NOT_MET, instance_datawriter->wait_for_acknowledgments(&data,
datawriter->get_instance_handle(), max_wait));
#endif // NDEBUG

// Access PublisherHistory
DataWriterTest* instance_datawriter_test = static_cast<DataWriterTest*>(instance_datawriter);
Expand Down

0 comments on commit 8a79678

Please sign in to comment.