From 72598404c950a8c12236007abdeeb7b537d55974 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 10 Feb 2025 19:49:20 +0100 Subject: [PATCH] Fix error handling logic in `try_setting_buffer_size` (#5631) * Refs #22208. Fix error handling logic in `try_setting_buffer_size`. Signed-off-by: Miguel Company * Refs #22756. Apply suggestion. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company --- src/cpp/rtps/transport/asio_helpers.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cpp/rtps/transport/asio_helpers.hpp b/src/cpp/rtps/transport/asio_helpers.hpp index b57d23d36ad..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) { @@ -70,9 +72,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; @@ -85,13 +87,14 @@ 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) + if (!ec && (option.value() >= value_to_set) && (option.value() <= max_value)) { final_buffer_value = option.value(); + return true; } - return true; } return false; }