fix: handle buffer capacity check correctly
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
9aa76857b0
commit
1659bf20d4
@@ -60,16 +60,14 @@ impl MetaPlugin for BinaryMetaPlugin {
|
|||||||
|
|
||||||
// Calculate how much data we can still accept
|
// Calculate how much data we can still accept
|
||||||
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
|
||||||
if remaining_capacity == 0 {
|
if remaining_capacity > 0 {
|
||||||
return;
|
// Determine how much data to copy
|
||||||
|
let bytes_to_take = std::cmp::min(data.len(), remaining_capacity);
|
||||||
|
|
||||||
|
// Add data to our buffer
|
||||||
|
self.buffer.extend_from_slice(&data[..bytes_to_take]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine how much data to copy
|
|
||||||
let bytes_to_take = std::cmp::min(data.len(), remaining_capacity);
|
|
||||||
|
|
||||||
// Add data to our buffer
|
|
||||||
self.buffer.extend_from_slice(&data[..bytes_to_take]);
|
|
||||||
|
|
||||||
// If we've reached our buffer limit, save the metadata immediately
|
// If we've reached our buffer limit, save the metadata immediately
|
||||||
if self.buffer.len() >= self.max_buffer_size {
|
if self.buffer.len() >= self.max_buffer_size {
|
||||||
let _ = self.save_metadata(conn);
|
let _ = self.save_metadata(conn);
|
||||||
|
|||||||
Reference in New Issue
Block a user