| 635 | //------------------------------------------------------------------------------ |
| 636 | |
| 637 | int main(int argc, char* argv[]) |
| 638 | { |
| 639 | // Check command line arguments. |
| 640 | if (argc != 5) |
| 641 | { |
| 642 | std::cerr << |
| 643 | "Usage: http-server-flex <address> <port> <doc_root> <threads>\n" << |
| 644 | "Example:\n" << |
| 645 | " http-server-flex 0.0.0.0 8080 .\n"; |
| 646 | return EXIT_FAILURE; |
| 647 | } |
| 648 | auto const address = net::ip::make_address(argv[1]); |
| 649 | auto const port = static_cast<unsigned short>(std::atoi(argv[2])); |
| 650 | auto const doc_root = std::make_shared<std::string>(argv[3]); |
| 651 | auto const threads = std::max<int>(1, std::atoi(argv[4])); |
| 652 | |
| 653 | // The io_context is required for all I/O |
| 654 | net::io_context ioc{threads}; |
| 655 | |
| 656 | // The SSL context is required, and holds certificates |
| 657 | ssl::context ctx{ssl::context::tlsv12}; |
| 658 | |
| 659 | // This holds the self-signed certificate used by the server |
| 660 | load_server_certificate(ctx); |
| 661 | |
| 662 | // Create and launch a listening port |
| 663 | std::make_shared<listener>( |
| 664 | ioc, |
| 665 | ctx, |
| 666 | tcp::endpoint{address, port}, |
| 667 | doc_root)->run(); |
| 668 | |
| 669 | // Run the I/O service on the requested number of threads |
| 670 | std::vector<std::thread> v; |
| 671 | v.reserve(threads - 1); |
| 672 | for(auto i = threads - 1; i > 0; --i) |
| 673 | v.emplace_back( |
| 674 | [&ioc] |
| 675 | { |
| 676 | ioc.run(); |
| 677 | }); |
| 678 | ioc.run(); |
| 679 | |
| 680 | return EXIT_SUCCESS; |
| 681 | } |
nothing calls this directly
no test coverage detected