| 272 | //------------------------------------------------------------------------------ |
| 273 | |
| 274 | int main(int argc, char* argv[]) |
| 275 | { |
| 276 | try |
| 277 | { |
| 278 | // Check command line arguments. |
| 279 | if (argc != 4) |
| 280 | { |
| 281 | std::cerr << |
| 282 | "Usage: http-server-sync-ssl <address> <port> <doc_root>\n" << |
| 283 | "Example:\n" << |
| 284 | " http-server-sync-ssl 0.0.0.0 8080 .\n"; |
| 285 | return EXIT_FAILURE; |
| 286 | } |
| 287 | auto const address = net::ip::make_address(argv[1]); |
| 288 | auto const port = static_cast<unsigned short>(std::atoi(argv[2])); |
| 289 | auto const doc_root = std::make_shared<std::string>(argv[3]); |
| 290 | |
| 291 | // The io_context is required for all I/O |
| 292 | net::io_context ioc{1}; |
| 293 | |
| 294 | // The SSL context is required, and holds certificates |
| 295 | ssl::context ctx{ssl::context::tlsv12}; |
| 296 | |
| 297 | // This holds the self-signed certificate used by the server |
| 298 | load_server_certificate(ctx); |
| 299 | |
| 300 | // The acceptor receives incoming connections |
| 301 | tcp::acceptor acceptor{ioc, {address, port}}; |
| 302 | for(;;) |
| 303 | { |
| 304 | // This will receive the new connection |
| 305 | tcp::socket socket{ioc}; |
| 306 | |
| 307 | // Block until we get a connection |
| 308 | acceptor.accept(socket); |
| 309 | |
| 310 | // Launch the session, transferring ownership of the socket |
| 311 | std::thread{std::bind( |
| 312 | &do_session, |
| 313 | std::move(socket), |
| 314 | std::ref(ctx), |
| 315 | doc_root)}.detach(); |
| 316 | } |
| 317 | } |
| 318 | catch (const std::exception& e) |
| 319 | { |
| 320 | std::cerr << "Error: " << e.what() << std::endl; |
| 321 | return EXIT_FAILURE; |
| 322 | } |
| 323 | } |
nothing calls this directly
no test coverage detected