storage/Interface: add virtual method OpenFile()

This should replace most InputStream::Open() calls because it is a
chance to reuse existing resources (e.g. the NFS connection).  No such
optimization is implemented, currently (and the method is not yet used
by anybody).
This commit is contained in:
Max Kellermann
2014-10-02 10:06:34 +02:00
committed by Max Kellermann
parent 2576e66a55
commit f578a1cb2b
11 changed files with 199 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
#include "lib/nfs/Lease.hxx"
#include "lib/nfs/Connection.hxx"
#include "lib/nfs/Glue.hxx"
#include "input/InputStream.hxx"
#include "fs/AllocatedPath.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
@@ -94,6 +95,8 @@ public:
[[nodiscard]] std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
InputStreamPtr OpenFile(std::string_view uri_utf8, Mutex &mutex) override;
/* virtual methods from NfsLease */
void OnNfsConnectionReady() noexcept final {
assert(state == State::CONNECTING);
@@ -246,6 +249,14 @@ NfsStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
return PathTraitsUTF8::Relative(base, uri_utf8);
}
InputStreamPtr
NfsStorage::OpenFile(std::string_view uri_utf8, Mutex &_mutex)
{
// TODO create NfsInputStream directly
auto uri = MapUTF8(uri_utf8);
return InputStream::Open(uri.c_str(), _mutex);
}
static void
Copy(StorageFileInfo &info, const struct nfs_stat_64 &st) noexcept
{