From f7790430a0323eadaaa8e0dacce24dda7331d583 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 31 Jul 2024 10:04:31 +0200 Subject: [PATCH] lib/curl/Multi: add SetSocketFunction(), SetTimerFunction() --- src/lib/curl/Global.cxx | 7 ++----- src/lib/curl/Multi.hxx | 12 ++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/curl/Global.cxx b/src/lib/curl/Global.cxx index fee17d7c9..8306399eb 100644 --- a/src/lib/curl/Global.cxx +++ b/src/lib/curl/Global.cxx @@ -84,11 +84,8 @@ CurlGlobal::CurlGlobal(EventLoop &_loop) :defer_read_info(_loop, BIND_THIS_METHOD(ReadInfo)), timeout_event(_loop, BIND_THIS_METHOD(OnTimeout)) { - multi.SetOption(CURLMOPT_SOCKETFUNCTION, CurlSocket::SocketFunction); - multi.SetOption(CURLMOPT_SOCKETDATA, this); - - multi.SetOption(CURLMOPT_TIMERFUNCTION, TimerFunction); - multi.SetOption(CURLMOPT_TIMERDATA, this); + multi.SetSocketFunction(CurlSocket::SocketFunction, this); + multi.SetTimerFunction(TimerFunction, this); } int diff --git a/src/lib/curl/Multi.hxx b/src/lib/curl/Multi.hxx index 8d237416d..116037f72 100644 --- a/src/lib/curl/Multi.hxx +++ b/src/lib/curl/Multi.hxx @@ -61,6 +61,18 @@ public: throw std::runtime_error(curl_multi_strerror(code)); } + void SetSocketFunction(int (*function)(CURL *easy, curl_socket_t s, int what, void *clientp, void *socketp) noexcept, + void *clientp) { + SetOption(CURLMOPT_SOCKETFUNCTION, function); + SetOption(CURLMOPT_SOCKETDATA, clientp); + } + + void SetTimerFunction(int (*function)(CURLM *multi, long timeout_ms, void *clientp) noexcept, + void *clientp) { + SetOption(CURLMOPT_TIMERFUNCTION, function); + SetOption(CURLMOPT_TIMERDATA, clientp); + } + void Add(CURL *easy) { auto code = curl_multi_add_handle(handle, easy); if (code != CURLM_OK)