aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/event/FullyBufferedSocket.cxx7
-rw-r--r--src/util/PeakBuffer.cxx14
-rw-r--r--src/util/PeakBuffer.hxx6
3 files changed, 16 insertions, 11 deletions
diff --git a/src/event/FullyBufferedSocket.cxx b/src/event/FullyBufferedSocket.cxx
index 87d29296e..9bb82a600 100644
--- a/src/event/FullyBufferedSocket.cxx
+++ b/src/event/FullyBufferedSocket.cxx
@@ -60,15 +60,14 @@ FullyBufferedSocket::Flush()
{
assert(IsDefined());
- size_t length;
- const void *data = output.Read(&length);
- if (data == nullptr) {
+ const auto data = output.Read();
+ if (data.IsNull()) {
IdleMonitor::Cancel();
CancelWrite();
return true;
}
- auto nbytes = DirectWrite(data, length);
+ auto nbytes = DirectWrite(data.data, data.size);
if (gcc_unlikely(nbytes <= 0))
return nbytes == 0;
diff --git a/src/util/PeakBuffer.cxx b/src/util/PeakBuffer.cxx
index a3659b8f4..7db1c97dc 100644
--- a/src/util/PeakBuffer.cxx
+++ b/src/util/PeakBuffer.cxx
@@ -45,19 +45,21 @@ PeakBuffer::IsEmpty() const
fifo_buffer_is_empty(peak_buffer));
}
-const void *
-PeakBuffer::Read(size_t *length_r) const
+ConstBuffer<void>
+PeakBuffer::Read() const
{
if (normal_buffer != nullptr) {
- const void *p = fifo_buffer_read(normal_buffer, length_r);
+ size_t size;
+ const void *p = fifo_buffer_read(normal_buffer, &size);
if (p != nullptr)
- return p;
+ return { p, size };
}
if (peak_buffer != nullptr) {
- const void *p = fifo_buffer_read(peak_buffer, length_r);
+ size_t size;
+ const void *p = fifo_buffer_read(peak_buffer, &size);
if (p != nullptr)
- return p;
+ return { p, size };
}
return nullptr;
diff --git a/src/util/PeakBuffer.hxx b/src/util/PeakBuffer.hxx
index a3f385e3e..0e58e80b8 100644
--- a/src/util/PeakBuffer.hxx
+++ b/src/util/PeakBuffer.hxx
@@ -20,11 +20,13 @@
#ifndef MPD_PEAK_BUFFER_HXX
#define MPD_PEAK_BUFFER_HXX
+#include "ConstBuffer.hxx"
#include "Compiler.h"
#include <stddef.h>
struct fifo_buffer;
+template<typename T> struct ConstBuffer;
/**
* A FIFO-like buffer that will allocate more memory on demand to
@@ -57,7 +59,9 @@ public:
gcc_pure
bool IsEmpty() const;
- const void *Read(size_t *length_r) const;
+ gcc_pure
+ ConstBuffer<void> Read() const;
+
void Consume(size_t length);
bool Append(const void *data, size_t length);