cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to retrieve "context" information in write/read callbacks?

From: Michal Marek <mmarek_at_suse.cz>
Date: Wed, 06 Feb 2008 18:25:08 +0100

Michal Marek wrote:
> Andrea Funtò wrote:
>> etc. A callback registering function looks like:
>> void set_my_callback(callback_function_ptr_t fx_ptr, void *
>> callback_data);
>> and when you actually use it in a C++ class, you can do something like:
>> set_my_callback(<static method of my class>, (void *)this);
>> so the "stub" callback you provide in the <static member of the class> can
>> go back to object orientation by grabbing and casting as appropriate the
>> callback_data.
>> Unfortunately I cannot see this feature in libcurl: if I register a write
>> callback with curl_easy_setopt(CURLOPT_WRITEFUNCTION), I can only provide a
>> pointer to the memory area to be filled by libcurl before invoking my
>> callback (through CURLOPT_WRITEDATA).
>
> ??
>
> How is
> curl_easy_setopt(CURLOPT_WRITEFUNCTION, <static method of my class>);
> curl_easy_setopt(CURLOPT_WRITEDATA, (void *)this);
> different from
> set_my_callback(<static method of my class>, (void *)this);
> ?

After reading your mail once more, I think you mixed up 'void *ptr' and
'void *stream' in
size_t function( void *ptr, size_t size, size_t nmemb, void *stream);

'ptr' points to the data to be written, 'stream' is the private pointer
you are looking for set by CURLOPT_WRITEDATA.

see
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEFUNCTION
for the details.

Michal
Received on 2008-02-06