From aeb2baa495776d9fc06e63f91167c40c334303c8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 29 Dec 2013 18:08:49 +0100 Subject: InputStream: add static method OpenReady() Merge some duplicate code. --- src/InputStream.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/InputStream.cxx') diff --git a/src/InputStream.cxx b/src/InputStream.cxx index 28a0aad1a..7d3ebe615 100644 --- a/src/InputStream.cxx +++ b/src/InputStream.cxx @@ -57,6 +57,28 @@ InputStream::Open(const char *url, return nullptr; } +InputStream * +InputStream::OpenReady(const char *uri, + Mutex &mutex, Cond &cond, + Error &error) +{ + InputStream *is = Open(uri, mutex, cond, error); + if (is == nullptr) + return nullptr; + + mutex.lock(); + is->WaitReady(); + bool success = is->Check(error); + mutex.unlock(); + + if (!success) { + is->Close(); + is = nullptr; + } + + return is; +} + bool InputStream::Check(Error &error) { -- cgit v1.2.3