File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 1111using namespace std ;
1212
1313int main (void ) {
14- httplib::Client (" http://localhost:1234" )
15- .Get (" /event1" , [&](const char *data, size_t data_length) {
16- std::cout << string (data, data_length);
17- return true ;
18- });
14+ std::vector<std::thread> threads;
15+
16+ size_t threead_count = 64 ;
17+
18+ for (size_t i = 0 ; i < threead_count; i++) {
19+ threads.push_back (std::thread{[&, i] {
20+ httplib::Client (" http://localhost:1234" )
21+ .Get (" /event1" , [&, i](const char *data, size_t data_length) {
22+ if (i == threead_count - 1 ) {
23+ std::cout << string (data, data_length);
24+ }
25+ return true ;
26+ });
27+ }});
28+ }
29+
30+ for (auto &t : threads) {
31+ t.join ();
32+ }
1933
2034 return 0 ;
2135}
Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ using namespace std;
1212
1313class EventDispatcher {
1414public:
15- EventDispatcher () {
16- }
15+ EventDispatcher () {}
1716
1817 void wait_event (DataSink *sink) {
1918 unique_lock<mutex> lk (m_);
@@ -64,6 +63,10 @@ int main(void) {
6463
6564 Server svr;
6665
66+ svr.new_task_queue = [] {
67+ return new ThreadPool (/* num_threads=*/ 128 , /* max_queued_requests=*/ 256 );
68+ };
69+
6770 svr.Get (" /" , [&](const Request & /* req*/ , Response &res) {
6871 res.set_content (html, " text/html" );
6972 });
You can’t perform that action at this time.
0 commit comments