summaryrefslogtreecommitdiff
path: root/src/lib/curl
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-01-08 14:30:34 +0100
committerMax Kellermann <max@musicpd.org>2017-01-08 14:36:27 +0100
commit1bab6d0dd763647b36f8190e2af833653ae0832f (patch)
treedc6a56b3b867306d680c2b9e5da053cc85c760af /src/lib/curl
parent13b85edbe2cb9bb864b819c41e79ac2cb1b78994 (diff)
lib/curl/Request: move catch clause out of FinishHeaders
Let the caller decide what to do with the exception.
Diffstat (limited to 'src/lib/curl')
-rw-r--r--src/lib/curl/Request.cxx27
-rw-r--r--src/lib/curl/Request.hxx2
2 files changed, 12 insertions, 17 deletions
diff --git a/src/lib/curl/Request.cxx b/src/lib/curl/Request.cxx
index ac791aa06..8bbb27c2a 100644
--- a/src/lib/curl/Request.cxx
+++ b/src/lib/curl/Request.cxx
@@ -114,32 +114,24 @@ CurlRequest::Resume()
global.InvalidateSockets();
}
-bool
+void
CurlRequest::FinishHeaders()
{
if (state != State::HEADERS)
- return true;
+ return;
state = State::BODY;
long status = 0;
curl_easy_getinfo(easy.Get(), CURLINFO_RESPONSE_CODE, &status);
- try {
- handler.OnHeaders(status, std::move(headers));
- return true;
- } catch (...) {
- state = State::CLOSED;
- handler.OnError(std::current_exception());
- return false;
- }
+ handler.OnHeaders(status, std::move(headers));
}
void
CurlRequest::FinishBody()
{
- if (!FinishHeaders())
- return;
+ FinishHeaders();
if (state != State::BODY)
return;
@@ -167,7 +159,12 @@ CurlRequest::Done(CURLcode result)
return;
}
- FinishBody();
+ try {
+ FinishBody();
+ } catch (...) {
+ state = State::CLOSED;
+ handler.OnError(std::current_exception());
+ }
}
inline void
@@ -221,10 +218,8 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size)
{
assert(received_size > 0);
- if (!FinishHeaders())
- return 0;
-
try {
+ FinishHeaders();
handler.OnData({ptr, received_size});
return received_size;
} catch (Pause) {
diff --git a/src/lib/curl/Request.hxx b/src/lib/curl/Request.hxx
index 5a6428db1..0b0a17f11 100644
--- a/src/lib/curl/Request.hxx
+++ b/src/lib/curl/Request.hxx
@@ -115,7 +115,7 @@ private:
*/
void FreeEasy();
- bool FinishHeaders();
+ void FinishHeaders();
void FinishBody();
size_t DataReceived(const void *ptr, size_t size);