cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Multithreaded Issues

From: Rob Mason <rmason_at_archivas.com>
Date: Tue, 24 Aug 2004 17:47:10 -0400

Thanks for the comments on my threading/programming practice, but it
really didn't address my real problem though. Any ideas on that part?

Some answers to the questions:
1) The naming scheme came from a curl example I found,
write_memory_callback writes memory which is for a CURL get (or read
from my point of view) and is used with the CURLOPT_WRITEFUNCTION
option.
2) I could do the stuct, but thats sort of irrelevant to my problem.
3) BIG_BUFFER_SIZE is 128KB and I can recreate this moving 1,000 byte
items, so this shouldn't have any impact. But out of curiosity the docs
that i've run into haven't indicated that I cant move less than curl is
ready to provide (unless I return none prematurely). I have moved sizes
much larger than 128KB without problems (when doing only PUTs or GETs)
so it "seems" ok.
4) I do clobber the data every time I'm called. Thats intentional and
should not be related to my problem.

Rob

> On Aug 24, 2004, at 5:02 PM, Daniel Stenberg wrote:
>
>> On Tue, 24 Aug 2004, Rob Mason wrote:
>>
>>> Read callback:
>>> static size_t write_memory_callback(void *ptr, size_t size, size_t
>>> nmemb, void *stream)
>>
>> I assume you mixed your labels so that this is the write callback! ;-)
>>
>>> thread_id = get_our_thread_id();
>>
>> I find your programming practise weird here. Why not pass in a
>> pointer to a struct in the stream argument and you won't have to
>> fetch the tread_id here.
>>
>>> if ((nmemb*size) > BIG_BUFFER_SIZE)
>>> {
>>> my_size = BIG_BUFFER_SIZE;
>>> }
>>
>> This looks very weird. How big is BIG_BUFFER_SIZE? Why don't you
>> allow larger buffer chunks? libcurl may send CURL_MAX_WRITE_SIZE
>> bytes at once.
>>
>> But if this condition is met, you'd return a different size than what
>> was passed in, and then libcurl would've stopped the transfer and
>> returned an error and since this doesn't happen I take it your
>> BIG_BUFFER_SIZE is at least big enough to very seldomly happen in
>> practise in your app.
>>
>>> if (my_size > 0)
>>> {
>>> memcpy(stream, ptr, my_size);
>>> }
>>
>> You copy the downloaded data to the same target buffer every time
>> this callback is called?
>>
>>> sizeLeft[thread_id] += my_size;
>>
>> ... and this is another global variable I would rather use a struct
>> to avoid, as described above.
>>
>> --
>> Daniel Stenberg -- http://curl.haxx.se -- http://daniel.haxx.se
>> Dedicated custom curl help for hire: http://haxx.se/curl.html
>>
>
Received on 2004-08-24