From edcd0b991386657a7572dddad7eafa616db087e1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 11 Jan 2018 20:50:16 +0100 Subject: [PATCH] lib/curl/Request: add methods StartIndirect(), StopIndirect() --- src/lib/curl/Request.cxx | 17 +++++++++++++++++ src/lib/curl/Request.hxx | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/lib/curl/Request.cxx b/src/lib/curl/Request.cxx index 919fc3456..204ee7d5b 100644 --- a/src/lib/curl/Request.cxx +++ b/src/lib/curl/Request.cxx @@ -32,6 +32,7 @@ #include "Global.hxx" #include "Version.hxx" #include "Handler.hxx" +#include "event/Call.hxx" #include "util/RuntimeError.hxx" #include "util/StringStrip.hxx" #include "util/StringView.hxx" @@ -80,6 +81,14 @@ CurlRequest::Start() registered = true; } +void +CurlRequest::StartIndirect() +{ + BlockingCall(global.GetEventLoop(), [this](){ + Start(); + }); +} + void CurlRequest::Stop() noexcept { @@ -90,6 +99,14 @@ CurlRequest::Stop() noexcept registered = false; } +void +CurlRequest::StopIndirect() +{ + BlockingCall(global.GetEventLoop(), [this](){ + Stop(); + }); +} + void CurlRequest::FreeEasy() noexcept { diff --git a/src/lib/curl/Request.hxx b/src/lib/curl/Request.hxx index 26cb9584b..a54c7c575 100644 --- a/src/lib/curl/Request.hxx +++ b/src/lib/curl/Request.hxx @@ -93,6 +93,11 @@ public: */ void Start(); + /** + * A thread-safe version of Start(). + */ + void StartIndirect(); + /** * Unregister this request via CurlGlobal::Remove(). * @@ -100,6 +105,11 @@ public: */ void Stop() noexcept; + /** + * A thread-safe version of Stop(). + */ + void StopIndirect(); + CURL *Get() noexcept { return easy.Get(); }