Re: using curl for a constant stream of event notifications
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.
[1]: https://curl.haxx.se/libcurl/c/getinmemory.html
[2]: https://gist.github.com/jay/f355d98e87fde19b1455b0b31dd118fd
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-07-11