| 274 | //------------------------------------------------------------------------------ |
| 275 | |
| 276 | int main(int argc, char* argv[]) |
| 277 | { |
| 278 | // Check command line arguments. |
| 279 | if (argc != 4) |
| 280 | { |
| 281 | std::cerr << |
| 282 | "Usage: websocket-server-async-ssl <address> <port> <threads>\n" << |
| 283 | "Example:\n" << |
| 284 | " websocket-server-async-ssl 0.0.0.0 8080 1\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 threads = std::max<int>(1, std::atoi(argv[3])); |
| 290 | |
| 291 | // The io_context is required for all I/O |
| 292 | net::io_context ioc{threads}; |
| 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 | // Create and launch a listening port |
| 301 | std::make_shared<listener>(ioc, ctx, tcp::endpoint{address, port})->run(); |
| 302 | |
| 303 | // Run the I/O service on the requested number of threads |
| 304 | std::vector<std::thread> v; |
| 305 | v.reserve(threads - 1); |
| 306 | for(auto i = threads - 1; i > 0; --i) |
| 307 | v.emplace_back( |
| 308 | [&ioc] |
| 309 | { |
| 310 | ioc.run(); |
| 311 | }); |
| 312 | ioc.run(); |
| 313 | |
| 314 | return EXIT_SUCCESS; |
| 315 | } |
nothing calls this directly
no test coverage detected