Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libcURL Progress Function not being called

Tags:

c++

libcurl

cURL version/OS in question is 7.15 and Red Hat 5, these are set in stone though so cannot change them.

The actual progress function which is not being called at all

int CurlUtil::progressCallback(void *clientp, double dltotal, double dlnow,
                           double ultotal, double ulnow)
{
   DEFN_METHOD_NAME( "progressCallback" );
   EX_ENTRY_EXIT();

   EX_DEBUG("Total downloaded " << dlnow << "/" << dltotal);
   EX_DEBUG("Total uploaded " << ulnow << "/" << ultotal);

   CurlUtil* curlUtil = (CurlUtil*)clientp;

   // If you return anything but 0, curl will abort transfer
   return (true == curlUtil->killed()) ? 1 : 0;
}

The setup code:

curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(m_curl, CURLOPT_PROGRESSFUNCTION, CurlUtil::progressCallback);
curl_easy_setopt(m_curl, CURLOPT_PROGRESSDATA, this)

Where CurlUtil is the class that the code exists in. The CURLOPT_DEBUGFUNCTION works fine and is set up in the exact same function in the same way.

like image 419
NolanPower Avatar asked Nov 10 '22 22:11

NolanPower


1 Answers

the problem is with calling convention of the call back function. It needs to __cdecl or /Gd option for gcc compilers. Please check compiler options if the function is already static. C++ member functions are called with thiscall calling conventions. Look at the following link, it provided more cleaner way if you want to have class that is responsible for handling transfer status and statistics: How can I use a member function pointer in libcurl

PS: My edit was slower as I was cross verifying. Hence posting as an answer.

like image 96
bsr Avatar answered Nov 14 '22 23:11

bsr