CppServer icon indicating copy to clipboard operation
CppServer copied to clipboard

[Question] Multiple SSLServer with a single Service

Open COM8 opened this issue 4 years ago • 0 comments
trafficstars

I would like to run two SSLServer instances (IPv4 and IPv6) in parallel. My first plan was to start both in the same thread and run them with the same Asio::Service. But when I do something like this:

asioService->Start();
sslServerIpv4->Start();
sslServerIpv6->Start();

while (shouldRun) {
    std::this_thread::sleep_for(std::chrono::seconds(1));
}

serverIpv4->Stop();
serverIpv6->Stop();
asioService->Stop();

it crashes at serverIpv6->Stop(); with the assertion assert(IsStarted() && "SSL server is not started!"); failing. Turns out, for the second server (serverIpv6) the auto start_handler = [this, self](){...} never gets called.

What else did I try:

  • Increase the number of threads when creating the Asio::Service and changing the pool option.
  • Create two threads and start a separate Asio::Service and SSLServer in each.

All with the same result, that the second server wont start.

What do I need to change to allow multiple servers running at the same time?

COM8 avatar Aug 04 '21 13:08 COM8