简体   繁体   中英

C - libcurl - How to get dltotal without using the CURLOPT_XFERINFOFUNCTION

I am using the libcurl multi interface and I need to know how much data is being sent for each request. I would rather not use the CURLOPT_XFERINFOFUNCTION because it gets called a lot and I only need to know the dltotal while I am in the CURLOPT_WRITEFUNCTION callback. I want to clean up the existing easy handle and malloc'd data while I am still in the write callback once all the data has been received. Is there a function I can call that will return the total amount of data that is being sent for a particular easy handle?

I tried using curl_easy_getinfo() with CURLINFO_SIZE_DOWNLOAD and it always returned 0 . I also tried CURLINFO_CONTENT_LENGTH_DOWNLOAD which also always returned 0 . I was calling this from within the CURLOPT_WRITEFUNCTION callback.

The reason you get zeroes back from those calls is probably because the size simply isn't known before-hand.

But let me also alert you that "I want to clean up the existing easy handle and malloc'd data while I am still in the write callback" sounds like a disaster waiting to happen. You really should not cleanup the handle from within the callback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM