MCPcopy Create free account
hub / github.com/chronoxor/CppServer / main

Function main

performance/http_trace_server.cpp:61–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59};
60
61int main(int argc, char** argv)
62{
63 auto parser = optparse::OptionParser().version("1.0.0.0");
64
65 parser.add_option("-p", "--port").dest("port").action("store").type("int").set_default(8080).help("Server port. Default: %default");
66 parser.add_option("-t", "--threads").dest("threads").action("store").type("int").set_default(CPU::PhysicalCores()).help("Count of working threads. Default: %default");
67
68 optparse::Values options = parser.parse_args(argc, argv);
69
70 // Print help
71 if (options.get("help"))
72 {
73 parser.print_help();
74 return 0;
75 }
76
77 // Server port
78 int port = options.get("port");
79 int threads = options.get("threads");
80
81 std::cout << "Server port: " << port << std::endl;
82 std::cout << "Working threads: " << threads << std::endl;
83
84 std::cout << std::endl;
85
86 // Create a new Asio service
87 auto service = std::make_shared<Service>(threads);
88
89 // Start the Asio service
90 std::cout << "Asio service starting...";
91 service->Start();
92 std::cout << "Done!" << std::endl;
93
94 // Create a new HTTP Trace server
95 auto server = std::make_shared<HTTPTraceServer>(service, port);
96 // server->SetupNoDelay(true);
97 server->SetupReuseAddress(true);
98 server->SetupReusePort(true);
99
100 // Start the server
101 std::cout << "Server starting...";
102 server->Start();
103 std::cout << "Done!" << std::endl;
104
105 std::cout << "Press Enter to stop the server or '!' to restart the server..." << std::endl;
106
107 // Perform text input
108 std::string line;
109 while (getline(std::cin, line))
110 {
111 if (line.empty())
112 break;
113
114 // Restart the server
115 if (line == "!")
116 {
117 std::cout << "Server restarting...";
118 server->Restart();

Callers

nothing calls this directly

Calls 7

getMethod · 0.45
StartMethod · 0.45
SetupReuseAddressMethod · 0.45
SetupReusePortMethod · 0.45
emptyMethod · 0.45
RestartMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected