| 469 | //------------------------------------------------------------------------------ |
| 470 | |
| 471 | int main(int argc, char* argv[]) |
| 472 | { |
| 473 | // Check command line arguments. |
| 474 | if (argc != 5) |
| 475 | { |
| 476 | std::cerr << |
| 477 | "Usage: http-server-stackless-ssl <address> <port> <doc_root> <threads>\n" << |
| 478 | "Example:\n" << |
| 479 | " http-server-stackless-ssl 0.0.0.0 8080 . 1\n"; |
| 480 | return EXIT_FAILURE; |
| 481 | } |
| 482 | auto const address = net::ip::make_address(argv[1]); |
| 483 | auto const port = static_cast<unsigned short>(std::atoi(argv[2])); |
| 484 | auto const doc_root = std::make_shared<std::string>(argv[3]); |
| 485 | auto const threads = std::max<int>(1, std::atoi(argv[4])); |
| 486 | |
| 487 | // The io_context is required for all I/O |
| 488 | net::io_context ioc{threads}; |
| 489 | |
| 490 | // The SSL context is required, and holds certificates |
| 491 | ssl::context ctx{ssl::context::tlsv12}; |
| 492 | |
| 493 | // This holds the self-signed certificate used by the server |
| 494 | load_server_certificate(ctx); |
| 495 | |
| 496 | // Create and launch a listening port |
| 497 | std::make_shared<listener>( |
| 498 | ioc, |
| 499 | ctx, |
| 500 | tcp::endpoint{address, port}, |
| 501 | doc_root)->run(); |
| 502 | |
| 503 | // Run the I/O service on the requested number of threads |
| 504 | std::vector<std::thread> v; |
| 505 | v.reserve(threads - 1); |
| 506 | for(auto i = threads - 1; i > 0; --i) |
| 507 | v.emplace_back( |
| 508 | [&ioc] |
| 509 | { |
| 510 | ioc.run(); |
| 511 | }); |
| 512 | ioc.run(); |
| 513 | |
| 514 | return EXIT_SUCCESS; |
| 515 | } |
nothing calls this directly
no test coverage detected