cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURLOPT_WRITEFUNCTION; Function not writing all data to disc file?

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Fri, 14 Jun 2013 08:56:51 +0200

On Thu, Jun 13, 2013 at 04:05:47PM +0100, Spencer Elliott wrote:
> I am very new to LibCurl, and am struggling with the CURLOPT_WRITEFUNCTION
> function.
>
> I have included my source code below, but essentially my issue is here:
>
> /*
>
> printf("\n");
>
> printf(response.c_str());
>
> printf("\n");
>
> LogToDisk(response);
>
> */
>
> The function that stores the data to a string seems to print the entire string
> out perfectly fine on the console using “printf”. However, when it saves to
> disc file, there is a large amount of text missing. Can anyone help me
> understand what I am doing wrong?

If the data made it in to the string, then libcurl transferred it successfully,
so this is not really a libcurl question any longer.

You didn't provide the source code to LogToDisk() but rather LogToDisc(); not sure
if that is relevant or just a typo. The code is passing the string by value,
not by reference, which is inefficient and for very, very large strings,
could fail due to lack of memory. It's also using another function you don't
explain, StrFormat. But, in using it, it's clear the string could be copied
internally an extra 3 times unnecessarily. If the data is particularly large,
then these 4 copies of the string could be using up all the available memory.
It could also be that this StrFormat function has an internal limit on the
maximum size of the string it can format.

>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-06-14