cURL / Mailing Lists / curl-library / Single Mail


Re: Avoid write callbacks

From: Dan Fandrich <>
Date: Wed, 13 Mar 2013 21:20:59 +0100

On Wed, Mar 13, 2013 at 01:01:35PM +0100, Florian Weimer wrote:
> Is there a way to avoid callbacks, while still supporting incremental
> retrieval of data?

Unless you're writing to a FILE*, libcurl gives no other option for
writing received data without using callbacks. But, you can certainly
wrap libcurl in such a way that the use of callbacks is hidden from the

> In a nutshell, I'm looking for an iterator-like
> interface.
> I could use the multi interface with a custom write function which
> writes to an in-memory buffer. I would run the event loop until that
> buffer contains some data. My iterator would return data from the
> buffer as long as some is available. It would run some iterations of
> the event loop to get more data.

That solution sounds perfectly doable. Take a look at the fopen.c example
program for an example of a libcurl wrapper that provides a stdio-like

> But I wonder if there is an easier way to accomplish this.

It sounds like the API you want doesn't quite match the API libcurl provides,
in which case some amount of code is going to be necessary to handle the
mismatch. It doesn't have to be a lot. Take a look also at the existing C++
binding (or bindings?) to see if that might not better suit you.

>>> Dan
List admin:
Received on 2013-03-13