input/curl: move code to SeekInternal(), simplify DoSeek()
Simplifies the code and reduces the number of IOThread roundtrips.
This commit is contained in:
parent
3e8cc2c670
commit
534e1fa6eb
@ -108,6 +108,11 @@ struct CurlInputStream final : public AsyncInputStream, CurlRequest {
|
|||||||
*/
|
*/
|
||||||
void FreeEasyIndirect();
|
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
|
* Called when a new response begins. This is used to discard
|
||||||
* headers from previous responses (for example authentication
|
* headers from previous responses (for example authentication
|
||||||
@ -497,32 +502,20 @@ CurlInputStream::InitEasy()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CurlInputStream::DoSeek(offset_type new_offset)
|
CurlInputStream::SeekInternal(offset_type new_offset)
|
||||||
{
|
{
|
||||||
assert(IsReady());
|
|
||||||
|
|
||||||
/* close the old connection and open a new one */
|
/* close the old connection and open a new one */
|
||||||
|
|
||||||
mutex.unlock();
|
FreeEasy();
|
||||||
|
|
||||||
FreeEasyIndirect();
|
|
||||||
|
|
||||||
offset = new_offset;
|
offset = new_offset;
|
||||||
if (offset == size) {
|
if (offset == size)
|
||||||
/* seek to EOF: simulate empty result; avoid
|
/* seek to EOF: simulate empty result; avoid
|
||||||
triggering a "416 Requested Range Not Satisfiable"
|
triggering a "416 Requested Range Not Satisfiable"
|
||||||
response */
|
response */
|
||||||
mutex.lock();
|
|
||||||
SeekDone();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
InitEasy();
|
||||||
InitEasy();
|
|
||||||
} catch (...) {
|
|
||||||
mutex.lock();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* send the "Range" header */
|
/* send the "Range" header */
|
||||||
|
|
||||||
@ -531,15 +524,19 @@ CurlInputStream::DoSeek(offset_type new_offset)
|
|||||||
easy.SetOption(CURLOPT_RANGE, range);
|
easy.SetOption(CURLOPT_RANGE, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
curl_global->Add(easy.Get(), *this);
|
||||||
input_curl_easy_add_indirect(this);
|
}
|
||||||
} catch (...) {
|
|
||||||
mutex.lock();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex.lock();
|
void
|
||||||
offset = new_offset;
|
CurlInputStream::DoSeek(offset_type new_offset)
|
||||||
|
{
|
||||||
|
assert(IsReady());
|
||||||
|
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
|
|
||||||
|
BlockingCall(io_thread_get(), [this, new_offset](){
|
||||||
|
SeekInternal(new_offset);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline InputStream *
|
inline InputStream *
|
||||||
|
Loading…
Reference in New Issue
Block a user