summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-01-03 08:18:46 +0100
committerMax Kellermann <max@musicpd.org>2017-01-03 10:50:02 +0100
commit534e1fa6eb32c0b22b86e6e803408593bbe42e28 (patch)
tree2aca8d8dc9fb8ae0c75be89b7133b4bc494347b2 /src
parent3e8cc2c67002a2915d8994209dd31dd6249e1215 (diff)
input/curl: move code to SeekInternal(), simplify DoSeek()
Simplifies the code and reduces the number of IOThread roundtrips.
Diffstat (limited to 'src')
-rw-r--r--src/input/plugins/CurlInputPlugin.cxx45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx
index 437fba56a..ad03ffc58 100644
--- a/src/input/plugins/CurlInputPlugin.cxx
+++ b/src/input/plugins/CurlInputPlugin.cxx
@@ -109,6 +109,11 @@ struct CurlInputStream final : public AsyncInputStream, CurlRequest {
void FreeEasyIndirect();
/**
+ * The DoSeek() implementation invoked in the IOThread.
+ */
+ void SeekInternal(offset_type new_offset);
+
+ /**
* Called when a new response begins. This is used to discard
* headers from previous responses (for example authentication
* and redirects).
@@ -497,32 +502,20 @@ CurlInputStream::InitEasy()
}
void
-CurlInputStream::DoSeek(offset_type new_offset)
+CurlInputStream::SeekInternal(offset_type new_offset)
{
- assert(IsReady());
-
/* close the old connection and open a new one */
- mutex.unlock();
-
- FreeEasyIndirect();
+ FreeEasy();
offset = new_offset;
- if (offset == size) {
+ if (offset == size)
/* seek to EOF: simulate empty result; avoid
triggering a "416 Requested Range Not Satisfiable"
response */
- mutex.lock();
- SeekDone();
return;
- }
- try {
- InitEasy();
- } catch (...) {
- mutex.lock();
- throw;
- }
+ InitEasy();
/* send the "Range" header */
@@ -531,15 +524,19 @@ CurlInputStream::DoSeek(offset_type new_offset)
easy.SetOption(CURLOPT_RANGE, range);
}
- try {
- input_curl_easy_add_indirect(this);
- } catch (...) {
- mutex.lock();
- throw;
- }
+ curl_global->Add(easy.Get(), *this);
+}
- mutex.lock();
- offset = new_offset;
+void
+CurlInputStream::DoSeek(offset_type new_offset)
+{
+ assert(IsReady());
+
+ const ScopeUnlock unlock(mutex);
+
+ BlockingCall(io_thread_get(), [this, new_offset](){
+ SeekInternal(new_offset);
+ });
}
inline InputStream *