curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: streaming data with libcurl

From: Rui Wang via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 26 Apr 2017 11:36:02 -0700

Hi Daniel,

Thanks for the reply!

Actually, I was blocked on how I could pass a callback to the writedata
callback. Last night I thought about this idea: there is a custom data
structure that I could parse into writedata function, in the example
'getinmemory' it only contains size and a pointer to the memory buffer that
holds the data. I could also include a function pointer field in this
structure, then I could have custom callback to execute when the data is
ready. I feel that conceptually this should work, but am not sure if I miss
anything. Do you think this works?

If it does, then I'm wondering about the pros and cons of this
implementation, compared with the approach that uses a separate consumer
thread with an extra queue. What I could think of:

1. with consumer thread and extra queue/pipe, there are more moving parts,
with callback it's more concise.
2. I'm not sure if libcurl calls writedata callback in a separate thread,
or it is single threaded. If the latter, then it might have negative impact
on throughput compared with the other approach.

Could you please educate me a little, especially on how "interleaved"
consumer works in multi interface?

Cheers,
Rui

On Wed, Apr 26, 2017 at 5:21 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Tue, 25 Apr 2017, Rui Wang via curl-library wrote:
>
> What I want to do is to process the attributes or the data as it arrives
>> instead of waiting for everything. I could use the writefunction to parse
>> the data and extracts attributes or data when it's ready. However, I can
>> only write that data to somewhere, but I can't pipe that data item into
>> another function since the function signature is already there.
>>
>
> Sorry but I can't parse this. You get the data in the callback, if you
> need or want to pass that data on to somewhere else, why can't you just do
> that?
>
> You could do it with a queue/pipe and the consumer of that could either
> run in a separate thread, or if you for example use the multi interface you
> could have it "interleaved" with the regular transfer. Whatever you think
> is best for you.
>
> What I could think of is to make a queue, and writefunction would send the
>> data item into the queue, another thread keeps checking the queue and
>> processes the element once it's there. This is way more complicated than
>> the callback, if it exists.
>>
>
> If you rather do a callback from within the callback, just do it!
>
> --
>
> / daniel.haxx.se
>

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-26