mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Updated README
This commit is contained in:
parent
2e360f9dd6
commit
f5e19faae7
2 changed files with 7 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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([&] {
|
||||
|
|
Loading…
Reference in a new issue