From 261a8f41eaa402ea7d0dfb2443e69b35f72eed4a Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 6 Feb 2025 14:27:55 +0100 Subject: [PATCH 1/2] Refs #22208. Fix error handling logic in `try_setting_buffer_size`. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/asio_helpers.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cpp/rtps/transport/asio_helpers.hpp b/src/cpp/rtps/transport/asio_helpers.hpp index b57d23d36ad..1cd90d86e01 100644 --- a/src/cpp/rtps/transport/asio_helpers.hpp +++ b/src/cpp/rtps/transport/asio_helpers.hpp @@ -70,9 +70,9 @@ struct asio_helpers final_buffer_value = option.value(); continue; } - // Could not determine the actual value, but the option was set successfully. - // Assume the option was set to the desired value. - return true; + // Could not determine the actual value, even though the option was set successfully. + // The current buffer size is not defined. + return false; } final_buffer_value /= 2; @@ -87,11 +87,11 @@ struct asio_helpers // Last attempt was successful. Get the actual value set. BufferOptionType option; socket.get_option(option, ec); - if (!ec) + if (!ec && (option.value() >= value_to_set)) { final_buffer_value = option.value(); + return true; } - return true; } return false; } From 776d3eb588874710735c80d36d61de8ff3204b44 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 10 Feb 2025 12:33:45 +0100 Subject: [PATCH 2/2] Refs #22756. Apply suggestion. Signed-off-by: Miguel Company --- src/cpp/rtps/transport/asio_helpers.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpp/rtps/transport/asio_helpers.hpp b/src/cpp/rtps/transport/asio_helpers.hpp index 1cd90d86e01..7eef3516c37 100644 --- a/src/cpp/rtps/transport/asio_helpers.hpp +++ b/src/cpp/rtps/transport/asio_helpers.hpp @@ -50,6 +50,8 @@ struct asio_helpers { asio::error_code ec; + assert(initial_buffer_value >= minimum_buffer_value); + final_buffer_value = initial_buffer_value; while (final_buffer_value > minimum_buffer_value) { @@ -85,9 +87,10 @@ struct asio_helpers if (!ec) { // Last attempt was successful. Get the actual value set. + int32_t max_value = static_cast(initial_buffer_value); BufferOptionType option; socket.get_option(option, ec); - if (!ec && (option.value() >= value_to_set)) + if (!ec && (option.value() >= value_to_set) && (option.value() <= max_value)) { final_buffer_value = option.value(); return true;