input/curl: hold mutex while writing to postponed_error

This commit is contained in:
Max Kellermann 2014-06-17 00:52:12 +02:00
parent e1d5ddb478
commit 8b84e5b3f9
3 changed files with 16 additions and 3 deletions

View File

@ -63,6 +63,16 @@ AsyncInputStream::Pause()
paused = true;
}
void
AsyncInputStream::PostponeError(Error &&error)
{
assert(io_thread_inside());
seek_state = SeekState::NONE;
postponed_error = std::move(error);
cond.broadcast();
}
inline void
AsyncInputStream::Resume()
{

View File

@ -86,6 +86,8 @@ protected:
open = false;
}
void PostponeError(Error &&error);
bool IsBufferEmpty() const {
return buffer.IsEmpty();
}

View File

@ -777,9 +777,10 @@ CurlInputStream::DoSeek(offset_type new_offset)
return;
}
Error error;
if (!InitEasy(postponed_error)) {
mutex.lock();
SeekDone();
PostponeError(std::move(error));
return;
}
@ -790,9 +791,9 @@ CurlInputStream::DoSeek(offset_type new_offset)
curl_easy_setopt(easy, CURLOPT_RANGE, range);
}
if (!input_curl_easy_add_indirect(this, postponed_error)) {
if (!input_curl_easy_add_indirect(this, error)) {
mutex.lock();
SeekDone();
PostponeError(std::move(error));
return;
}