curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: using curl for a constant stream of event notifications

From: Ray Satiro via curl-library <>
Date: Thu, 11 Jul 2019 00:37:27 -0400

On 7/9/2019 12:43 PM, R C via curl-library wrote:
> I have been using the curl library, to write some c code for for
> accessing IoT devices.
> Some of these devices can produce a "constant stream" of event
> notifications,  in text/xml.
> I wonder what the best approach would be to open such a stream and
> keep reading it.
> (probably close it once in a while, and restart that event stream.
> any suggestions for a "best practices" approach?

Every time the write callback is called append the received data in a
buffer (like example [1]), parse that buffer for complete notifications,
notify of those notifications and then remove that data from the buffer
(like example [2]).

If your app's notification process is anything other than quick then I
suggest push the notifications asynchronously by instead copying the
notification to some location where it can be later consumed by your
app. The reason for this is you don't want to slow down the curl event
loop from receiving data from the server and writing it to memory.


Received on 2019-07-11