MCPcopy Create free account
hub / github.com/boostorg/beast / main

Function main

example/http/server/async-ssl/http_server_async_ssl.cpp:490–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488//------------------------------------------------------------------------------
489
490int main(int argc, char* argv[])
491{
492 // Check command line arguments.
493 if (argc != 5)
494 {
495 std::cerr <<
496 "Usage: http-server-async-ssl <address> <port> <doc_root> <threads>\n" <<
497 "Example:\n" <<
498 " http-server-async-ssl 0.0.0.0 8080 . 1\n";
499 return EXIT_FAILURE;
500 }
501 auto const address = net::ip::make_address(argv[1]);
502 auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
503 auto const doc_root = std::make_shared<std::string>(argv[3]);
504 auto const threads = std::max<int>(1, std::atoi(argv[4]));
505
506 // The io_context is required for all I/O
507 net::io_context ioc{threads};
508
509 // The SSL context is required, and holds certificates
510 ssl::context ctx{ssl::context::tlsv12};
511
512 // This holds the self-signed certificate used by the server
513 load_server_certificate(ctx);
514
515 // Create and launch a listening port
516 std::make_shared<listener>(
517 ioc,
518 ctx,
519 tcp::endpoint{address, port},
520 doc_root)->run();
521
522 // Run the I/O service on the requested number of threads
523 std::vector<std::thread> v;
524 v.reserve(threads - 1);
525 for(auto i = threads - 1; i > 0; --i)
526 v.emplace_back(
527 [&ioc]
528 {
529 ioc.run();
530 });
531 ioc.run();
532
533 return EXIT_SUCCESS;
534}

Callers

nothing calls this directly

Calls 2

load_server_certificateFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected