Skip to content

Commit

Permalink
lib/curl/Multi: add SetSocketFunction(), SetTimerFunction()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jul 31, 2024
1 parent 009c24b commit f06320c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/lib/curl/Global.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,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);
}

void
Expand Down
12 changes: 12 additions & 0 deletions src/lib/curl/Multi.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f06320c

Please sign in to comment.