aboutsummaryrefslogtreecommitdiffstats
path: root/src/InotifySource.cxx
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/InotifySource.cxx
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/InotifySource.cxx')
-rw-r--r--src/InotifySource.cxx30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/InotifySource.cxx b/src/InotifySource.cxx
index 587625d3d..bf292af60 100644
--- a/src/InotifySource.cxx
+++ b/src/InotifySource.cxx
@@ -20,7 +20,6 @@
#include "config.h"
#include "InotifySource.hxx"
#include "InotifyDomain.hxx"
-#include "util/fifo_buffer.h"
#include "util/Error.hxx"
#include "system/fd_util.h"
#include "system/FatalError.hxx"
@@ -34,30 +33,27 @@
bool
InotifySource::OnSocketReady(gcc_unused unsigned flags)
{
- void *dest;
- size_t length;
- ssize_t nbytes;
-
- dest = fifo_buffer_write(buffer, &length);
- if (dest == NULL)
+ const auto dest = buffer.Write();
+ if (dest.IsEmpty())
FatalError("buffer full");
- nbytes = read(Get(), dest, length);
+ ssize_t nbytes = read(Get(), dest.data, dest.size);
if (nbytes < 0)
FatalSystemError("Failed to read from inotify");
if (nbytes == 0)
FatalError("end of file from inotify");
- fifo_buffer_append(buffer, nbytes);
+ buffer.Append(nbytes);
while (true) {
const char *name;
+ auto range = buffer.Read();
const struct inotify_event *event =
(const struct inotify_event *)
- fifo_buffer_read(buffer, &length);
- if (event == NULL || length < sizeof(*event) ||
- length < sizeof(*event) + event->len)
+ range.data;
+ if (range.size < sizeof(*event) ||
+ range.size < sizeof(*event) + event->len)
break;
if (event->len > 0 && event->name[event->len - 1] == 0)
@@ -66,7 +62,7 @@ InotifySource::OnSocketReady(gcc_unused unsigned flags)
name = NULL;
callback(event->wd, event->mask, name, callback_ctx);
- fifo_buffer_consume(buffer, sizeof(*event) + event->len);
+ buffer.Consume(sizeof(*event) + event->len);
}
return true;
@@ -77,8 +73,7 @@ InotifySource::InotifySource(EventLoop &_loop,
mpd_inotify_callback_t _callback, void *_ctx,
int _fd)
:SocketMonitor(_fd, _loop),
- callback(_callback), callback_ctx(_ctx),
- buffer(fifo_buffer_new(4096))
+ callback(_callback), callback_ctx(_ctx)
{
ScheduleRead();
@@ -98,11 +93,6 @@ InotifySource::Create(EventLoop &loop,
return new InotifySource(loop, callback, callback_ctx, fd);
}
-InotifySource::~InotifySource()
-{
- fifo_buffer_free(buffer);
-}
-
int
InotifySource::Add(const char *path_fs, unsigned mask, Error &error)
{