Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Jan 18, 2020
1 parent 2e360f9 commit f5e19fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions example/sse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EventDispatcher {
cid_ = -1;
}

void add_sink(DataSink *sink) {
void wait_event(DataSink *sink) {
unique_lock<mutex> lk(m_);
int id = id_;
cv_.wait(lk, [&] { return cid_ == id; });
Expand Down Expand Up @@ -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([&] {
Expand Down

0 comments on commit f5e19fa

Please sign in to comment.