Skip to content

Commit

Permalink
Fix error handling logic in try_setting_buffer_size (#5631)
Browse files Browse the repository at this point in the history
* Refs #22208. Fix error handling logic in `try_setting_buffer_size`.

Signed-off-by: Miguel Company <[email protected]>

* Refs #22756. Apply suggestion.

Signed-off-by: Miguel Company <[email protected]>

---------

Signed-off-by: Miguel Company <[email protected]>
(cherry picked from commit 7259840)
  • Loading branch information
MiguelCompany authored and mergify[bot] committed Feb 10, 2025
1 parent fd8d24e commit ce188d3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cpp/rtps/transport/asio_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -85,13 +87,14 @@ struct asio_helpers
if (!ec)
{
// Last attempt was successful. Get the actual value set.
int32_t max_value = static_cast<int32_t>(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;
}
Expand Down

0 comments on commit ce188d3

Please sign in to comment.