Hey
Responding to a forwarded message and I'm not subscribed. Excuse the
formatting. I'm the lead developer of libcurl and was asked to comment on
this.
>> From: Alex Balashov <abalashov(a)evaristesys.com>
>> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
>>
>> As far as I can tell from how write_function() is constructed, it expects
>> to be called once:
>> 1) Does this function need to be rewritten to realloc() and concatenate?
Yes. libcurl will deliver data to the callback as soon as it has read some off
the network, it can thus deliver one byte at a time during slow conditions or
a whole bunch. It will keep calling the callback as long as data is coming.
This is also documented in the man page:
http://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html
>> 2) Is there an option in CURL that can use internal buffering and only
>> invoke the callback once all the response chunks are received?
Nope.
>> 3) Would increasing the curl.h constant CURL_MAX_WRITE_SIZE help?
No. That would just make libcurl able to read a larger chunk from the socket
into its own buffer, but it wouldn't prevent it from calling the callback one
or many times.
--
/ daniel.haxx.se
Hi,
I have a ~21 kB HTTP response that I need to handle with http_query()
from the utils module.
There are two separate obstacles to this. The first is insufficient size
of the default PV text buffer, which is solvable by increasing it using
the 'pv_buffer_size' core parameter.
The second is the CURL wrapper in modules/utils/functions.c itself. It
uses the write_function() callback to pump the data into a buffer:
char *stream;
...
stream = NULL;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
As far as I can tell from how write_function() is constructed, it
expects to be called once:
size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream)
{
/* Allocate memory and copy */
char* data;
data = (char*)pkg_malloc((size* nmemb) + 1);
if (data == NULL) {
LM_ERR("cannot allocate memory for stream\n");
return CURLE_WRITE_ERROR;
}
memcpy(data, (char*)ptr, size* nmemb);
data[nmemb] = '\0';
*((char**) stream) = data;
return size* nmemb;
}
That's not the case for a 21 kB reply:
size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream)
{
/* Allocate memory and copy */
char* data;
LM_INFO("Write function called with additional buffer: %u\n",
(unsigned int) size * nmemb);
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 1193
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 1448
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 10136
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 1448
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 1448
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 4344
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 1448
0(9696) INFO: utils [functions.c:56]: write_function(): Write function
called with additional buffer: 327
So, I'm not sure what the easiest way to go here is.
1) Does this function need to be rewritten to realloc() and concatenate?
2) Is there an option in CURL that can use internal buffering and only
invoke the callback once all the response chunks are received?
3) Would increasing the curl.h constant CURL_MAX_WRITE_SIZE help?
Input is appreciated!
-- Alex
--
Alex Balashov - Principal
Evariste Systems LLC
235 E Ponce de Leon Ave
Suite 106
Decatur, GA 30030
United States
Tel: +1-678-954-0670
Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.
The following task has a new comment added:
FS#497 - dialplan: Reload failure
User who did this - Olle Johansson (oej)
----------
When disabling dB-text caching I can't repeat this. Nice. My problem, not the code.
I still need to try with mysql where I saw the problem first.
----------
More information can be found at the following URL:
http://sip-router.org/tracker/index.php?do=details&task_id=497#comment1736
You are receiving this message because you have requested it from the Flyspray bugtracking system. If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.