util/PeakBuffer: use IsEmpty() instead of IsNull()

The DynamicFifoBuffer methods never return nullptr when the buffer is
empty or full; instead, they return an empty buffer.  This bug caused
an endless loop.
This commit is contained in:
Max Kellermann 2013-12-19 10:30:26 +01:00
parent f544316314
commit 52dca859c7
2 changed files with 4 additions and 4 deletions

View File

@ -60,7 +60,7 @@ FullyBufferedSocket::Flush()
assert(IsDefined()); assert(IsDefined());
const auto data = output.Read(); const auto data = output.Read();
if (data.IsNull()) { if (data.IsEmpty()) {
IdleMonitor::Cancel(); IdleMonitor::Cancel();
CancelWrite(); CancelWrite();
return true; return true;

View File

@ -43,13 +43,13 @@ PeakBuffer::Read() const
{ {
if (normal_buffer != nullptr) { if (normal_buffer != nullptr) {
const auto p = normal_buffer->Read(); const auto p = normal_buffer->Read();
if (!p.IsNull()) if (!p.IsEmpty())
return p.ToVoid(); return p.ToVoid();
} }
if (peak_buffer != nullptr) { if (peak_buffer != nullptr) {
const auto p = peak_buffer->Read(); const auto p = peak_buffer->Read();
if (!p.IsNull()) if (!p.IsEmpty())
return p.ToVoid(); return p.ToVoid();
} }
@ -85,7 +85,7 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer, const void *data, size_t length)
do { do {
const auto p = buffer.Write(); const auto p = buffer.Write();
if (p.IsNull()) if (p.IsEmpty())
break; break;
const size_t nbytes = std::min(length, p.size); const size_t nbytes = std::min(length, p.size);