curl / Mailing Lists / curl-library / Single Mail


streaming data with libcurl

From: Rui Wang via curl-library <>
Date: Tue, 25 Apr 2017 17:28:48 -0700

Hi Folks,

I'm trying to process some binary data stream with libcurl. The data format
is like the following:

4 bytes header that contains length of attributes, then attributes, then 8
bytes header that contains length of data, then data.

Both attributes and data are optional. So it could be 4bytes followed by
attributes, then 8bytes that contains a 0, another 4 bytes followed by
attributes, and so on.

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. I don't
know if I could have a custom callback function triggered once the data
item is ready just like the writefunction. That would be the most efficient
way to handle the incoming stream.

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.

I'm not familiar with libcurl and this seems to be a very common use case.
I am wondering if I'm missing something obvious. If anyone wants to give me
a hand, I'll really appreciate. :-)


Received on 2017-04-26