curl-library
Re: Is the callback specified in CURLOPT_WRITEFUNCTION thread-safe?
Date: Thu, 3 Jul 2014 00:12:34 +0530
Hi Dan, thanks for the reply ..
On Wed, Jul 2, 2014 at 1:11 AM, Dan Fandrich <dan_at_coneharvesters.com> wrote:
> On Tue, Jul 01, 2014 at 09:14:24PM +0530, Ajay Garg wrote:
> > Is it safe to pass the same callback-function as the parameter to
> > CURLOPT_WRITEFUNCTION in different threads?
> > Note that the threads may be highly concurrent, sending and receiving
> requests/
> > responses simultaneously.
> >
> > Or we run the risk of mixing up received-data (in different threads)?
>
> This is entirely up to the callback function. libcurl is thread safe when
> used
> in the recommended way. One of those stipulations is that a libcurl handle
> must
> not be shared between threads.
Yes, we are not sharing any libcurl handles between threads.
> If that's followed there will never be an
> opportunity to mix up received data since the handle passed in to the
> callback
> in each thread will be different.
>
You mean the "ptr" handle is different for each thread, in the callback of
type:
size_t write_callback(char *ptr, size_t size, size_t
nmemb, void *userdata);
?
>
> >>> Dan
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
-- Regards, Ajay
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-07-02