Skip to content

Commit 7259840

Browse files
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 <[email protected]> * Refs #22756. Apply suggestion. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]>
1 parent 406a0a5 commit 7259840

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/cpp/rtps/transport/asio_helpers.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ struct asio_helpers
5050
{
5151
asio::error_code ec;
5252

53+
assert(initial_buffer_value >= minimum_buffer_value);
54+
5355
final_buffer_value = initial_buffer_value;
5456
while (final_buffer_value > minimum_buffer_value)
5557
{
@@ -70,9 +72,9 @@ struct asio_helpers
7072
final_buffer_value = option.value();
7173
continue;
7274
}
73-
// Could not determine the actual value, but the option was set successfully.
74-
// Assume the option was set to the desired value.
75-
return true;
75+
// Could not determine the actual value, even though the option was set successfully.
76+
// The current buffer size is not defined.
77+
return false;
7678
}
7779

7880
final_buffer_value /= 2;
@@ -85,13 +87,14 @@ struct asio_helpers
8587
if (!ec)
8688
{
8789
// Last attempt was successful. Get the actual value set.
90+
int32_t max_value = static_cast<int32_t>(initial_buffer_value);
8891
BufferOptionType option;
8992
socket.get_option(option, ec);
90-
if (!ec)
93+
if (!ec && (option.value() >= value_to_set) && (option.value() <= max_value))
9194
{
9295
final_buffer_value = option.value();
96+
return true;
9397
}
94-
return true;
9598
}
9699
return false;
97100
}

0 commit comments

Comments
 (0)