cURL / Mailing Lists / curl-library / Single Mail


Re: Curl from multiple threads and callback functions

From: Andreas Volz <>
Date: Wed, 2 Jan 2008 09:38:16 +0100

Am Tue, 1 Jan 2008 15:25:05 -0800 schrieb Dan Fandrich:

> On Tue, Jan 01, 2008 at 11:29:43PM +0100, Andreas Volz wrote:
> > In my application I generate a dynamic number of download threads.
> > My problem is the static writer callback. For each CURL handle I
> > would need a new callback function at compile time. But I know the
> > number of CURL handles only at runtime. Do you understand my
> > problem? Any ideas how to solve it?
> I'm afraid I don't understand the problem. You can set a new callback
> function for each handle if you want to, but why do you need to?
> You can pass in a unique datum into the static callback using the
> CURLOPT_WRITEDATA option, and use that to perform different behaviour
> in the callback on a per-handle basis.

Ok, that is a good idea. Until now I pass only the file handle into the
callback. If I give a struct into the callback it should work. Thanks
for that hint.

I read that curl is thread save, So does curl only call the callback
once the same time if I use curl from multiple threads? Or do I need to
protect the callback with a mutex?

Received on 2008-01-02