curl / Mailing Lists / curl-library / Single Mail


Libcurl server-sent events (SSE) write callback notification

From: Chris Dolfin via curl-library <>
Date: Wed, 13 Feb 2019 16:41:32 -0500

I am trying to understand how to implement licburl client to process server
sent events

SSE; W3C Recommendation, January 2015

Libcurl always call the “write callback” when it receives HTTP response and
stores the data in the structure provided by the user.

In normal request curl_easy_perform(,,) returns and I know that there is
data in my buffer.

The pseudo code for normal libcurl flow

// initialize


curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

res = curl_easy_perform(curl);

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.

How do I get notification that there is data waiting for me?

I cannot call curl_easy_perform() because I should not send new request.

Received on 2019-02-14