cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Multithreaded Issues

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Tue, 24 Aug 2004 23:02:44 +0200 (CEST)

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