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

Function main

example/cpp11/http/server4/main.cpp:17–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include "file_handler.hpp"
16
17int main(int argc, char* argv[])
18{
19 try
20 {
21 // Check command line arguments.
22 if (argc != 4)
23 {
24 std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
25 std::cerr << " For IPv4, try:\n";
26 std::cerr << " receiver 0.0.0.0 80 .\n";
27 std::cerr << " For IPv6, try:\n";
28 std::cerr << " receiver 0::0 80 .\n";
29 return 1;
30 }
31
32 boost::asio::io_context io_context;
33
34 // Launch the initial server coroutine.
35 http::server4::server(io_context, argv[1], argv[2],
36 http::server4::file_handler(argv[3]))();
37
38 // Wait for signals indicating time to shut down.
39 boost::asio::signal_set signals(io_context);
40 signals.add(SIGINT);
41 signals.add(SIGTERM);
42#if defined(SIGQUIT)
43 signals.add(SIGQUIT);
44#endif // defined(SIGQUIT)
45 signals.async_wait(
46 [&io_context](boost::system::error_code, int)
47 {
48 io_context.stop();
49 });
50
51 // Run the server.
52 io_context.run();
53 }
54 catch (std::exception& e)
55 {
56 std::cerr << "exception: " << e.what() << "\n";
57 }
58
59 return 0;
60}

Callers

nothing calls this directly

Calls 6

file_handlerClass · 0.85
serverClass · 0.70
addMethod · 0.45
async_waitMethod · 0.45
stopMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected