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

Function main

example/http/server/async-local/http_server_async_local.cpp:395–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393//------------------------------------------------------------------------------
394
395int main(int argc, char* argv[])
396{
397 try
398 {
399 // Check command line arguments.
400 if (argc != 4)
401 {
402 std::cerr <<
403 "Usage: http-server-async-local <path> <doc_root> <threads>\n" <<
404 "Example:\n" <<
405 " http-server-async-local /tmp/http.sock . 1\n";
406 return EXIT_FAILURE;
407 }
408 auto const path = argv[1];
409 auto const doc_root = std::make_shared<std::string>(argv[2]);
410 auto const threads = std::max<int>(1, std::atoi(argv[3]));
411
412 // The io_context is required for all I/O
413 net::io_context ioc{threads};
414
415 // Remove previous binding
416 std::remove(path);
417
418 // Create and launch a listening port
419 std::make_shared<listener>(
420 ioc,
421 stream_protocol::endpoint{path},
422 doc_root)->run();
423
424 // Run the I/O service on the requested number of threads
425 std::vector<std::thread> v;
426 v.reserve(threads - 1);
427 for(auto i = threads - 1; i > 0; --i)
428 v.emplace_back(
429 [&ioc]
430 {
431 ioc.run();
432 });
433 ioc.run();
434
435 return EXIT_SUCCESS;
436 }
437 catch(std::exception const& e)
438 {
439 std::cerr << e.what() << std::endl;
440 return EXIT_FAILURE;
441 }
442}
443
444#else
445

Callers

nothing calls this directly

Calls 2

whatMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected