aboutsummaryrefslogtreecommitdiffstats
path: root/src/InputStream.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-29 18:08:49 +0100
committerMax Kellermann <max@duempel.org>2013-12-29 18:08:49 +0100
commitaeb2baa495776d9fc06e63f91167c40c334303c8 (patch)
tree4bbd926c1f19a64a1f3fc5b580d0d68bd3aabca3 /src/InputStream.cxx
parentea9aff1d3f9f68eb5ae9e5f2bd67d283b8c0f47e (diff)
downloadmpd-aeb2baa495776d9fc06e63f91167c40c334303c8.tar.gz
mpd-aeb2baa495776d9fc06e63f91167c40c334303c8.tar.xz
mpd-aeb2baa495776d9fc06e63f91167c40c334303c8.zip
InputStream: add static method OpenReady()
Merge some duplicate code.
Diffstat (limited to '')
-rw-r--r--src/InputStream.cxx22
1 files changed, 22 insertions, 0 deletions
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)
{