NOT-OMEGA commited on
Commit
619a0e4
·
verified ·
1 Parent(s): c05cb0f

Update main.cpp

Browse files
Files changed (1) hide show
  1. main.cpp +12 -4
main.cpp CHANGED
@@ -573,18 +573,26 @@ int main(int argc, char* argv[]) {
573
  asio::io_context ioc(static_cast<int>(threads));
574
 
575
  auto ep = tcp::endpoint(asio::ip::make_address("0.0.0.0"), port);
 
 
576
  std::cout << "[CollabDocs] Listening on 0.0.0.0:" << port
577
- << " (" << threads << " threads)\n";
 
 
 
578
 
579
  // Run listener in background thread
580
  std::thread listener_thread([&]{ do_listen(ioc, ep); });
581
 
582
  // Thread pool
583
  std::vector<std::thread> pool;
584
- pool.reserve(threads - 1);
585
- for (unsigned i = 0; i < threads - 1; ++i)
586
- pool.emplace_back([&]{ ioc.run(); });
 
 
587
 
 
588
  ioc.run();
589
 
590
  for (auto& t : pool) t.join();
 
573
  asio::io_context ioc(static_cast<int>(threads));
574
 
575
  auto ep = tcp::endpoint(asio::ip::make_address("0.0.0.0"), port);
576
+
577
+ // FIX 1: std::endl forces the log to print immediately
578
  std::cout << "[CollabDocs] Listening on 0.0.0.0:" << port
579
+ << " (" << threads << " threads)" << std::endl;
580
+
581
+ // FIX 2: THIS KEEPS THE SERVER ALIVE
582
+ auto work_guard = asio::make_work_guard(ioc);
583
 
584
  // Run listener in background thread
585
  std::thread listener_thread([&]{ do_listen(ioc, ep); });
586
 
587
  // Thread pool
588
  std::vector<std::thread> pool;
589
+ if (threads > 1) {
590
+ pool.reserve(threads - 1);
591
+ for (unsigned i = 0; i < threads - 1; ++i)
592
+ pool.emplace_back([&]{ ioc.run(); });
593
+ }
594
 
595
+ // Now this will stay running and process your HTTP/WebSocket requests
596
  ioc.run();
597
 
598
  for (auto& t : pool) t.join();