cURL / Mailing Lists / curl-library / Single Mail


Re: Is the callback specified in CURLOPT_WRITEFUNCTION thread-safe?

From: Dan Fandrich <>
Date: Wed, 2 Jul 2014 21:34:18 +0200

On Thu, Jul 03, 2014 at 12:12:34AM +0530, Ajay Garg wrote:
> On Wed, Jul 2, 2014 at 1:11 AM, Dan Fandrich <> wrote:
> 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);

ptr will point to a different internal libcurl buffer for each curl handle, and
since these handles are never shared between threads, yes, it will be different
in each thread. The userdata pointer will be whatever was set on the handle by
the application, so it can be different in each thread as well, if desired.

>>> Dan
List admin:
Received on 2014-07-02