Skip to content

Commit

Permalink
curl: no longer using the deprecated CURLOPT_PROGRESSFUNCTION, instea…
Browse files Browse the repository at this point in the history
…d switched to CURLOPT_XFERINFOFUNCTION.
  • Loading branch information
mikekazakov committed Dec 17, 2024
1 parent 533c4a7 commit 5ac8544
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/VFS/source/NetFTP/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void File::FinishReading()
assert(m_Mode == Mode::Read);

// tell curl to cancel any going reading if any
m_CURL->prog_func = ^(double, double, double, double) {
m_CURL->prog_func = ^(curl_off_t, curl_off_t, curl_off_t, curl_off_t) {
return 1;
};

Expand Down
2 changes: 1 addition & 1 deletion Source/VFS/source/NetFTP/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int FTPHost::DownloadListing(CURLInstance *_inst,
_inst->EasySetOpt(CURLOPT_WRITEFUNCTION, CURLWriteDataIntoString);
_inst->EasySetOpt(CURLOPT_WRITEDATA, &response);
_inst->EasySetupProgFunc();
_inst->prog_func = ^(double, double, double, double) {
_inst->prog_func = ^(curl_off_t, curl_off_t, curl_off_t, curl_off_t) {
if( _cancel_checker == nil )
return 0;
return _cancel_checker() ? 1 : 0;
Expand Down
10 changes: 7 additions & 3 deletions Source/VFS/source/NetFTP/Internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,27 @@ CURLMcode CURLInstance::Detach()
return e;
}

int CURLInstance::ProgressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
int CURLInstance::ProgressCallback(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow)
{
CURLInstance *_this = static_cast<CURLInstance *>(clientp);
return _this->prog_func ? _this->prog_func(dltotal, dlnow, ultotal, ulnow) : 0;
}

void CURLInstance::EasySetupProgFunc()
{
EasySetOpt(CURLOPT_PROGRESSFUNCTION, ProgressCallback);
EasySetOpt(CURLOPT_XFERINFOFUNCTION, ProgressCallback);
EasySetOpt(CURLOPT_PROGRESSDATA, this);
EasySetOpt(CURLOPT_NOPROGRESS, 0);
prog_func = nil;
}

void CURLInstance::EasyClearProgFunc()
{
EasySetOpt(CURLOPT_PROGRESSFUNCTION, nullptr);
EasySetOpt(CURLOPT_XFERINFOFUNCTION, nullptr);
EasySetOpt(CURLOPT_PROGRESSDATA, nullptr);
EasySetOpt(CURLOPT_NOPROGRESS, 1);
prog_func = nil;
Expand Down
5 changes: 3 additions & 2 deletions Source/VFS/source/NetFTP/Internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ struct CURLInstance {
CURL *curl = nullptr;
CURLM *curlm = nullptr;
bool attached = false;
int (^prog_func)(double dltotal, double dlnow, double ultotal, double ulnow) = nil;
int (^prog_func)(curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) = nil;
std::mutex call_lock;

private:
static int ProgressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
static int
ProgressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
};

// ReadBuffer provides an intermediatery storage where CURL can write to so that a File can read from afterwards
Expand Down

0 comments on commit 5ac8544

Please sign in to comment.