Updated README

This commit is contained in:
yhirose 2020-01-17 23:21:42 -05:00
parent 2e360f9dd6
commit f5e19faae7
2 changed files with 7 additions and 3 deletions

View file

@ -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

View file

@ -23,7 +23,7 @@ public:
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; });
@ -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([&] {