From 5aa3aca3089fc70c2ecb853134ba90a464adf0de Mon Sep 17 00:00:00 2001 From: Jesus Perez Date: Tue, 5 Mar 2024 11:15:33 +0100 Subject: [PATCH] Refs #20589: Set real non_blocking_send limitation Signed-off-by: Jesus Perez --- src/cpp/rtps/transport/TCPChannelResource.cpp | 3 ++- test/unittest/transport/TCPv4Tests.cpp | 6 ++++-- test/unittest/transport/TCPv6Tests.cpp | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cpp/rtps/transport/TCPChannelResource.cpp b/src/cpp/rtps/transport/TCPChannelResource.cpp index 315e9f6cbe0..d24dfc3d0f1 100644 --- a/src/cpp/rtps/transport/TCPChannelResource.cpp +++ b/src/cpp/rtps/transport/TCPChannelResource.cpp @@ -310,7 +310,8 @@ bool TCPChannelResource::check_socket_send_buffer( size_t future_queue_size = size_t(bytesInSendQueue) + msg_size; - if (future_queue_size > size_t(parent_->configuration()->sendBufferSize)) + // TCP actually allocates twice the size of the buffer requested. + if (future_queue_size > size_t(2 * parent_->configuration()->sendBufferSize)) { return false; } diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index a4445c49b08..dd3d7a35ef8 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -1521,7 +1521,8 @@ TEST_F(TCPv4Tests, secure_non_blocking_send) const octet* data = message.data(); size_t size = message.size(); - // Send the message with no header + // Send the message with no header. Since TCP actually allocates twice the size of the buffer requested + // and we want to guarantee that the buffer might be full, we send the message more than twice. for (int i = 0; i < 5; i++) { sender_channel_resource->send(nullptr, 0, data, size, ec); @@ -2019,7 +2020,8 @@ TEST_F(TCPv4Tests, non_blocking_send) const octet* data = message.data(); size_t size = message.size(); - // Send the message with no header + // Send the message with no header. Since TCP actually allocates twice the size of the buffer requested + // and we want to guarantee that the buffer might be full, we send the message more than twice. for (int i = 0; i < 5; i++) { sender_channel_resource->send(nullptr, 0, data, size, ec); diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index b86f0286031..d8020db4ab6 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -371,7 +371,8 @@ TEST_F(TCPv6Tests, non_blocking_send) const octet* data = message.data(); size_t size = message.size(); - // Send the message with no header + // Send the message with no header. Since TCP actually allocates twice the size of the buffer requested + // and we want to guarantee that the buffer might be full, we send the message more than twice. for (int i = 0; i < 5; i++) { sender_channel_resource->send(nullptr, 0, data, size, ec);