aboutsummaryrefslogtreecommitdiffstats
path: root/src/event/BufferedSocket.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-15 10:28:52 +0200
committerMax Kellermann <max@duempel.org>2013-10-15 10:28:52 +0200
commit84d20d9e433028125bfe36557ad54a28b97914b2 (patch)
tree9c0b9469ac91e14b90eebd08b5a04ba3a9f3b4a3 /src/event/BufferedSocket.hxx
parent0c13703da3641951bf061cac7c5cef034eda16f9 (diff)
downloadmpd-84d20d9e433028125bfe36557ad54a28b97914b2.tar.gz
mpd-84d20d9e433028125bfe36557ad54a28b97914b2.tar.xz
mpd-84d20d9e433028125bfe36557ad54a28b97914b2.zip
util/FifoBuffer: C++ version of the fifo_buffer library
Diffstat (limited to 'src/event/BufferedSocket.hxx')
-rw-r--r--src/event/BufferedSocket.hxx16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/event/BufferedSocket.hxx b/src/event/BufferedSocket.hxx
index 578000961..31d6c3c57 100644
--- a/src/event/BufferedSocket.hxx
+++ b/src/event/BufferedSocket.hxx
@@ -22,8 +22,12 @@
#include "check.h"
#include "SocketMonitor.hxx"
+#include "util/FifoBuffer.hxx"
#include "Compiler.h"
+#include <assert.h>
+#include <stdint.h>
+
struct fifo_buffer;
class Error;
@@ -31,16 +35,14 @@ class Error;
* A #SocketMonitor specialization that adds an input buffer.
*/
class BufferedSocket : protected SocketMonitor {
- fifo_buffer *input;
+ FifoBuffer<uint8_t, 8192> input;
public:
BufferedSocket(int _fd, EventLoop &_loop)
- :SocketMonitor(_fd, _loop), input(nullptr) {
+ :SocketMonitor(_fd, _loop) {
ScheduleRead();
}
- ~BufferedSocket();
-
using SocketMonitor::IsDefined;
using SocketMonitor::Close;
using SocketMonitor::Write;
@@ -67,7 +69,11 @@ protected:
* does not invalidate the pointer passed to OnSocketInput()
* yet.
*/
- void ConsumeInput(size_t nbytes);
+ void ConsumeInput(size_t nbytes) {
+ assert(IsDefined());
+
+ input.Consume(nbytes);
+ }
enum class InputResult {
/**