cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to avoid static function in c++ when calling CURLOPT_WRITEFUNCTION

From: Stephen Collyer <scollyer_at_netspinner.co.uk>
Date: Tue, 23 Sep 2008 10:32:11 +0100

Meir Yanovich wrote:
> Hello all
> im using curl in my application and its c++ application
> im encapsulate the curl init in class and i like to avoid using static
> member function
> for better multi threaded and OOP support .
> but i have problem when i pass the call back function into
> CURLOPT_WRITEFUNCTION
> it accepts only static function , is there away to pass it not static
> call back function ?
> Thanks

Yes, it's possible to pass a member function as a callback to
CURLOPT_WRITEFUNCTION. The fundamental trick is to pass a pointer
to a member function which is bound to a particular object, which
you can do with code like:

> ProgressCallback cb =
> std::bind1st(std::mem_fun(&FileTransferScheduler::progress_callback),
> this);

where ProgressCallback looks like:

> typedef struct
> {
> double bytes_to_transfer;
> double bytes_transferred;
> }
> ProgressData;
>
> typedef boost::function<bool (ProgressData)> ProgressCallback;

I've posted more details about this in past so if you search
the list you should find all you need to know.

-- 
Regards
Steve Collyer
Netspinner Ltd
Received on 2008-09-24