From f5e19faae7495e52e44dc2e81ac8d17d17b6b760 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 17 Jan 2020 23:21:42 -0500 Subject: [PATCH] Updated README --- README.md | 4 ++++ example/sse.cc | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8af941..03d3b79 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,10 @@ svr.Get("/chunked", [&](const Request& req, Response& res) { }); ``` +### Server-Sent Events + +Please check [here](https://github.com/yhirose/cpp-httplib/blob/master/example/sse.cc). + ### Default thread pool support diff --git a/example/sse.cc b/example/sse.cc index 7a876f7..7aa7ad7 100644 --- a/example/sse.cc +++ b/example/sse.cc @@ -23,7 +23,7 @@ public: cid_ = -1; } - void add_sink(DataSink *sink) { + void wait_event(DataSink *sink) { unique_lock lk(m_); int id = id_; cv_.wait(lk, [&] { return cid_ == id; }); @@ -80,14 +80,14 @@ int main(void) { cout << "connected to event1..." << endl; res.set_header("Content-Type", "text/event-stream"); res.set_chunked_content_provider( - [&](uint64_t /*offset*/, DataSink &sink) { ed.add_sink(&sink); }); + [&](uint64_t /*offset*/, DataSink &sink) { ed.wait_event(&sink); }); }); svr.Get("/event2", [&](const Request & /*req*/, Response &res) { cout << "connected to event2..." << endl; res.set_header("Content-Type", "text/event-stream"); res.set_chunked_content_provider( - [&](uint64_t /*offset*/, DataSink &sink) { ed.add_sink(&sink); }); + [&](uint64_t /*offset*/, DataSink &sink) { ed.wait_event(&sink); }); }); thread t([&] {