I am using libcurl in my code and the first few attempts of curl_easy_perform() returns proper values but after that I see that the first 800 or so bytes are dropped. The pointer write_data function is passed starts out pointing to the stream after the first 800 bytes or so.
Here is the snippet of code I use –
ctx = curl_easy_init();
curl_easy_setopt(ctx, CURLOPT_POSTFIELDS, bodyData);
curl_easy_setopt(ctx, CURLOPT_URL, serverUrl);
curl_easy_setopt(ctx, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(ctx, CURLOPT_WRITEDATA, response);
res = curl_easy_perform(ctx);
curl_easy_cleanup(ctx);
EDIT: Ok so I see that for some requests, the write_data is called twice for the one curl_easy_perform(). So write_data gets the first x bytes and then reading the remaining in the next time. But my write_data function is overriding the response pointer everytime. How do I know if I need to memcpy or concatenate to the response pointer? I hope I am able to describe the situation properly.
Thanks
P
You need to provide a large buffer (your “response” pointer) and every time your write_data function is called you would append more data to the buffer. Your response pointer should probably point to struct, something like this:
Then, on every entry into the write_data function you want to memcpy the supplied data into the buffer after the last position you wrote to (remember, the supplied buffer to write_data is not necessarily null terminated), e.g:
Something like that should do it. (disclaimer: I’ve not bothered to try compiling this, but it should work)