diff options
author | Max Kellermann <max@duempel.org> | 2014-08-06 17:20:03 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-08-06 17:20:03 +0200 |
commit | 1f3d3970f672ec9b200ed358e2d02c45c97c34eb (patch) | |
tree | 8f10eab21a6b28081b62f99de9d2ad939d740836 /src/db | |
parent | c9a71a7176f13cbd86c8270c523c0e506b2ab424 (diff) | |
download | mpd-1f3d3970f672ec9b200ed358e2d02c45c97c34eb.tar.gz mpd-1f3d3970f672ec9b200ed358e2d02c45c97c34eb.tar.xz mpd-1f3d3970f672ec9b200ed358e2d02c45c97c34eb.zip |
db/update/InotifySource: remove FifoBuffer
Eliminate support for partial reads. The Linux kernel will never
return partial results, so this buffering was unnecessary.
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/update/InotifySource.cxx | 28 | ||||
-rw-r--r-- | src/db/update/InotifySource.hxx | 3 |
2 files changed, 15 insertions, 16 deletions
diff --git a/src/db/update/InotifySource.cxx b/src/db/update/InotifySource.cxx index c2783690e..233504ad6 100644 --- a/src/db/update/InotifySource.cxx +++ b/src/db/update/InotifySource.cxx @@ -25,43 +25,45 @@ #include "system/FatalError.hxx" #include "Log.hxx" +#include <algorithm> + #include <sys/inotify.h> #include <unistd.h> #include <errno.h> +#include <stdint.h> +#include <limits.h> bool InotifySource::OnSocketReady(gcc_unused unsigned flags) { - const auto dest = buffer.Write(); - if (dest.IsEmpty()) - FatalError("buffer full"); + uint8_t buffer[4096]; + static_assert(sizeof(buffer) >= sizeof(struct inotify_event) + NAME_MAX + 1, + "inotify buffer too small"); - ssize_t nbytes = read(Get(), dest.data, dest.size); + ssize_t nbytes = read(Get(), buffer, sizeof(buffer)); if (nbytes < 0) FatalSystemError("Failed to read from inotify"); if (nbytes == 0) FatalError("end of file from inotify"); - buffer.Append(nbytes); + const uint8_t *p = buffer, *const end = p + nbytes; while (true) { - const char *name; - - auto range = buffer.Read(); + const size_t remaining = end - p; const struct inotify_event *event = - (const struct inotify_event *) - range.data; - if (range.size < sizeof(*event) || - range.size < sizeof(*event) + event->len) + (const struct inotify_event *)p; + if (remaining < sizeof(*event) || + remaining < sizeof(*event) + event->len) break; + const char *name; if (event->len > 0 && event->name[event->len - 1] == 0) name = event->name; else name = nullptr; callback(event->wd, event->mask, name, callback_ctx); - buffer.Consume(sizeof(*event) + event->len); + p += sizeof(*event) + event->len; } return true; diff --git a/src/db/update/InotifySource.hxx b/src/db/update/InotifySource.hxx index 77c11093c..081ce10f3 100644 --- a/src/db/update/InotifySource.hxx +++ b/src/db/update/InotifySource.hxx @@ -21,7 +21,6 @@ #define MPD_INOTIFY_SOURCE_HXX #include "event/SocketMonitor.hxx" -#include "util/FifoBuffer.hxx" class Error; @@ -32,8 +31,6 @@ class InotifySource final : private SocketMonitor { mpd_inotify_callback_t callback; void *callback_ctx; - FifoBuffer<uint8_t, 4096> buffer; - InotifySource(EventLoop &_loop, mpd_inotify_callback_t callback, void *ctx, int fd); |