From 73dc8ff6bd39fd4df8dea8f2ea0a79f4c1844018 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 17 Nov 2022 06:13:40 +0100 Subject: [PATCH] lib/nfs/FileReader: pass std::span to OnNfsFileRead() --- src/input/plugins/NfsInputPlugin.cxx | 8 ++++---- src/lib/nfs/FileReader.cxx | 5 ++++- src/lib/nfs/FileReader.hxx | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/input/plugins/NfsInputPlugin.cxx b/src/input/plugins/NfsInputPlugin.cxx index 45bd6a54e..12da41ab0 100644 --- a/src/input/plugins/NfsInputPlugin.cxx +++ b/src/input/plugins/NfsInputPlugin.cxx @@ -71,7 +71,7 @@ protected: private: /* virtual methods from NfsFileReader */ void OnNfsFileOpen(uint64_t size) noexcept override; - void OnNfsFileRead(const void *data, size_t size) noexcept override; + void OnNfsFileRead(std::span src) noexcept override; void OnNfsFileError(std::exception_ptr &&e) noexcept override; }; @@ -159,14 +159,14 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept } void -NfsInputStream::OnNfsFileRead(const void *data, size_t data_size) noexcept +NfsInputStream::OnNfsFileRead(std::span src) noexcept { const std::scoped_lock protect(mutex); assert(!IsBufferFull()); assert(IsBufferFull() == (GetBufferSpace() == 0)); - AppendToBuffer(data, data_size); + AppendToBuffer(src.data(), src.size()); - next_offset += data_size; + next_offset += src.size(); DoRead(); } diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx index aedc35d8b..2b9ed491d 100644 --- a/src/lib/nfs/FileReader.cxx +++ b/src/lib/nfs/FileReader.cxx @@ -239,7 +239,10 @@ NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept break; case State::READ: - OnNfsFileRead(data, status); + OnNfsFileRead({ + static_cast(data), + static_cast(status), + }); break; } } diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx index c941c57c7..10fffb6e5 100644 --- a/src/lib/nfs/FileReader.hxx +++ b/src/lib/nfs/FileReader.hxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -125,7 +126,7 @@ protected: * * This method will be called from within the I/O thread. */ - virtual void OnNfsFileRead(const void *data, size_t size) noexcept = 0; + virtual void OnNfsFileRead(std::span src) noexcept = 0; /** * An error has occurred, which can be either while waiting