From 1e3089ffb770c9f8e62769c9384cf699ee395cf5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 11 Dec 2020 14:04:16 +0100 Subject: [PATCH] curl/Request: move struct Pause to class CurlResponseHandler --- src/input/plugins/CurlInputPlugin.cxx | 2 +- src/lib/curl/Handler.hxx | 9 +++++++++ src/lib/curl/Request.cxx | 2 +- src/lib/curl/Request.hxx | 6 ------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 3cdab5653..98c372a0f 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -309,7 +309,7 @@ CurlInputStream::OnData(ConstBuffer data) if (data.size > GetBufferSpace()) { AsyncInputStream::Pause(); - throw CurlRequest::Pause(); + throw CurlResponseHandler::Pause{}; } AppendToBuffer(data.data, data.size); diff --git a/src/lib/curl/Handler.hxx b/src/lib/curl/Handler.hxx index 153b50603..ad5001e11 100644 --- a/src/lib/curl/Handler.hxx +++ b/src/lib/curl/Handler.hxx @@ -43,6 +43,13 @@ */ class CurlResponseHandler { public: + /** + * OnData() shall throw this to pause the stream. Call + * CurlEasy::Unpause() or CurlRequest::Resume() to resume the + * transfer. + */ + struct Pause {}; + /** * Status line and headers have been received. */ @@ -51,6 +58,8 @@ public: /** * Response body data has been received. + * + * May throw #Pause. */ virtual void OnData(ConstBuffer data) = 0; diff --git a/src/lib/curl/Request.cxx b/src/lib/curl/Request.cxx index 2253c5a4f..1f1c59940 100644 --- a/src/lib/curl/Request.cxx +++ b/src/lib/curl/Request.cxx @@ -241,7 +241,7 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size) noexcept FinishHeaders(); handler.OnData({ptr, received_size}); return received_size; - } catch (Pause) { + } catch (CurlResponseHandler::Pause) { return CURL_WRITEFUNC_PAUSE; } catch (...) { state = State::CLOSED; diff --git a/src/lib/curl/Request.hxx b/src/lib/curl/Request.hxx index ef6ef02c9..abc2a46a7 100644 --- a/src/lib/curl/Request.hxx +++ b/src/lib/curl/Request.hxx @@ -146,12 +146,6 @@ public: easy.SetRequestBody(data, size); } - /** - * CurlResponseHandler::OnData() shall throw this to pause the - * stream. Call Resume() to resume the transfer. - */ - struct Pause {}; - void Resume() noexcept; /**