yhirose/cpp-httplib

How to start in a thread?

qwe857359351a opened this issue · 2 comments

For Windows.
After calling the listen function, the thread is blocked, causing some subsequent services to be unable to be processed.
After I started the thread, I couldn't receive the request and the test tool was always loading.
But after removing the thread, I could receive the request. Through the console, I can view the process corresponding to the port.
Here is the code:

svr.Post("/cmd", http_handler);
auto thread = std::thread([&]() { 
  printf("server start success");
  svr.listen(HOST, PORT); 
});

auto se = detail::scope_exit([&] {
  svr.stop();
  thread.join();
});

svr.wait_until_ready();
while(true) {
  getchar();
}

You can see a number of examples in test/test.cc. Hope it helps.

You can see a number of examples in test/test.cc. Hope it helps.

Thinks!