curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Libcurl server-sent events (SSE) write callback notification

From: Chris Dolfin via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 14 Feb 2019 15:14:19 -0500

>> At this stage I know that there is data in readBuffer.
>> At this stage the server will send more data and WriteCallback will be
>> called to write data to readBuffer.
>
>No.
>
>For these long-going HTTP streams, curl_easy_perform() will not return
until
>the connection closes and that might take a long time until it does.

Is my application going to block on curl_easy_perform() in this case?

> And for
>most situaitons, I would imagine that you'd just loop then and do another
>request again to allow for more "events" to arrive.

This is what I an unable to understand.
Which library call do I loop around? curl_easy_perform() ?
Which request do I send again? Do I make a request to the library or
another curl_easy_perform() but curl_easy_perform() will send new subscribe
request that I don not wont to send.

>While curl_easy_perform() sits waiting for more events nothing happens but
as
>soon as data arrives it will call the write callback and your application
can
>deal with it.

How do I get notified that the write callback has finished assembling the
message and I can read the full message?

Unfortunately my streaming HTTP server is not operational at this time and
I am unable to see the behavior. When it was working I was able to use curl
command line utility to subscribe and it was working great displaying
messages send by the server.

Thank you for your help
Chris

On Thu, Feb 14, 2019 at 3:08 AM Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Wed, 13 Feb 2019, Chris Dolfin via curl-library wrote:
>
> > http://www.w3.org/TR/eventsource
>
> To me, this is just a HTTP stream that may potentially stick around for a
> long
> time. Nothing strange for libcurl.
>
> > Libcurl always call the “write callback” when it receives HTTP response
> and
> > stores the data in the structure provided by the user.
>
> Yes. Well libcurl calls the callback zero, one or many times, whether the
> application stores that data or not is of course entirely up to it.
>
> > In normal request curl_easy_perform(,,) returns and I know that there is
> > data in my buffer.
>
> If it returned ok, the response data had a non-zero length and your
> callback
> stored it, sure.
>
> > At this stage I know that there is data in readBuffer.
> >
> > At this stage the server will send more data and WriteCallback will be
> > called to write data to readBuffer.
>
> No.
>
> For these long-going HTTP streams, curl_easy_perform() will not return
> until
> the connection closes and that might take a long time until it does. And
> for
> most situaitons, I would imagine that you'd just loop then and do another
> request again to allow for more "events" to arrive.
>
> While curl_easy_perform() sits waiting for more events nothing happens but
> as
> soon as data arrives it will call the write callback and your application
> can
> deal with it.
>
> > I cannot call curl_easy_perform() because I should not send new request.
>
> If the connection breaks I figure you should...
>
> --
>
> / daniel.haxx.se

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-02-14