| 419 | //------------------------------------------------------------------------------ |
| 420 | |
| 421 | int main(int argc, char* argv[]) |
| 422 | { |
| 423 | // Check command line arguments. |
| 424 | if (argc != 4) |
| 425 | { |
| 426 | std::cerr << |
| 427 | "Usage: websocket-server-fast <address> <starting-port> <threads>\n" << |
| 428 | "Example:\n" |
| 429 | " websocket-server-fast 0.0.0.0 8080 1\n" |
| 430 | " Connect to:\n" |
| 431 | " starting-port+0 for synchronous,\n" |
| 432 | " starting-port+1 for asynchronous,\n" |
| 433 | " starting-port+2 for coroutine.\n"; |
| 434 | return EXIT_FAILURE; |
| 435 | } |
| 436 | auto const address = net::ip::make_address(argv[1]); |
| 437 | auto const port = static_cast<unsigned short>(std::atoi(argv[2])); |
| 438 | auto const threads = std::max<int>(1, std::atoi(argv[3])); |
| 439 | |
| 440 | // The io_context is required for all I/O |
| 441 | net::io_context ioc{threads}; |
| 442 | |
| 443 | // Create sync port |
| 444 | std::thread(beast::bind_front_handler( |
| 445 | &do_sync_listen, |
| 446 | std::ref(ioc), |
| 447 | tcp::endpoint{ |
| 448 | address, |
| 449 | static_cast<unsigned short>(port + 0u)} |
| 450 | )).detach(); |
| 451 | |
| 452 | // Create async port |
| 453 | std::make_shared<async_listener>( |
| 454 | ioc, |
| 455 | tcp::endpoint{ |
| 456 | address, |
| 457 | static_cast<unsigned short>(port + 1u)})->run(); |
| 458 | |
| 459 | // Create coro port |
| 460 | boost::asio::spawn(ioc, |
| 461 | std::bind( |
| 462 | &do_coro_listen, |
| 463 | std::ref(ioc), |
| 464 | tcp::endpoint{ |
| 465 | address, |
| 466 | static_cast<unsigned short>(port + 2u)}, |
| 467 | std::placeholders::_1), boost::asio::detached); |
| 468 | |
| 469 | // Run the I/O service on the requested number of threads |
| 470 | std::vector<std::thread> v; |
| 471 | v.reserve(threads - 1); |
| 472 | for(auto i = threads - 1; i > 0; --i) |
| 473 | v.emplace_back( |
| 474 | [&ioc] |
| 475 | { |
| 476 | ioc.run(); |
| 477 | }); |
| 478 | ioc.run(); |
nothing calls this directly
no test coverage detected