m_downloader(downloader),
m_id(id),
m_url(url),
- m_handle(curl_easy_init()),
+ m_handle(),
m_error_buffer(),
m_status(new TransferStatus(id))
{
+ m_handle = curl_easy_init();
if (!m_handle)
{
throw std::runtime_error("curl_easy_init() failed");
curl_easy_setopt(m_handle, CURLOPT_USERAGENT, "SuperTux/" PACKAGE_VERSION " libcURL");
curl_easy_setopt(m_handle, CURLOPT_WRITEDATA, this);
- curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION,
- [](void* ptr, size_t size, size_t nmemb, void* userdata) -> size_t
- {
- return static_cast<Transfer*>(userdata)
- ->on_data(ptr, size, nmemb);
- });
+ curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, &Transfer::on_data_wrap);
curl_easy_setopt(m_handle, CURLOPT_ERRORBUFFER, m_error_buffer.data());
curl_easy_setopt(m_handle, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(m_handle, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(m_handle, CURLOPT_XFERINFODATA, this);
- curl_easy_setopt(m_handle, CURLOPT_XFERINFOFUNCTION,
- [](void* userdata,
- curl_off_t dltotal, curl_off_t dlnow,
- curl_off_t ultotal, curl_off_t ulnow)
- {
- return static_cast<Transfer*>(userdata)
- ->on_progress(dltotal, dlnow,
- ultotal, ulnow);
- });
+ curl_easy_setopt(m_handle, CURLOPT_XFERINFOFUNCTION, &Transfer::on_progress_wrap);
}
}
size_t on_data(void* ptr, size_t size, size_t nmemb)
{
- return size * nmemb;;
+ return size * nmemb;
}
void on_progress(curl_off_t dltotal, curl_off_t dlnow,
}
private:
+ static size_t on_data_wrap(char* ptr, size_t size, size_t nmemb, void* userdata)
+ {
+ return static_cast<Transfer*>(userdata)->on_data(ptr, size, nmemb);
+ }
+
+ static void on_progress_wrap(void* userdata,
+ curl_off_t dltotal, curl_off_t dlnow,
+ curl_off_t ultotal, curl_off_t ulnow)
+ {
+ return static_cast<Transfer*>(userdata)->on_progress(dltotal, dlnow, ultotal, ulnow);
+ }
+
+private:
Transfer(const Transfer&) = delete;
Transfer& operator=(const Transfer&) = delete;
};