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

@@ -6,6 +6,9 @@
#include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx"
#include "storage/MemoryDirectoryReader.hxx"
#include "input/InputStream.hxx"
#include "input/RewindInputStream.hxx"
#include "input/plugins/CurlInputPlugin.hxx"
#include "lib/curl/HttpStatusError.hxx"
#include "lib/curl/Init.hxx"
#include "lib/curl/Global.hxx"
@@ -52,6 +55,8 @@ public:
[[nodiscard]] std::string MapUTF8(std::string_view uri_utf8) const noexcept override;
[[nodiscard]] std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept override;
InputStreamPtr OpenFile(std::string_view uri_utf8, Mutex &mutex) override;
};
std::string
@@ -71,6 +76,12 @@ CurlStorage::MapToRelativeUTF8(std::string_view uri_utf8) const noexcept
CurlUnescape(uri_utf8));
}
InputStreamPtr
CurlStorage::OpenFile(std::string_view uri_utf8, Mutex &mutex)
{
return input_rewind_open(OpenCurlInputStream(MapUTF8(uri_utf8), {}, mutex));
}
class BlockingHttpRequest : protected CurlResponseHandler {
InjectEvent defer_start;