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

Function main

performance/https_trace_server.cpp:61–142  ·  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(8443).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 and prepare a new SSL server context
95 auto context = std::make_shared<SSLContext>(asio::ssl::context::tlsv13);
96 context->set_password_callback([](size_t max_length, asio::ssl::context::password_purpose purpose) -> std::string { return "qwerty"; });
97 context->use_certificate_chain_file("../tools/certificates/server.pem");
98 context->use_private_key_file("../tools/certificates/server.pem", asio::ssl::context::pem);
99 context->use_tmp_dh_file("../tools/certificates/dh4096.pem");
100
101 // Create a new HTTPS Trace server
102 auto server = std::make_shared<HTTPSTraceServer>(service, context, port);
103 // server->SetupNoDelay(true);
104 server->SetupReuseAddress(true);
105 server->SetupReusePort(true);
106
107 // Start the server
108 std::cout << "Server starting...";
109 server->Start();
110 std::cout << "Done!" << std::endl;
111
112 std::cout << "Press Enter to stop the server or '!' to restart the server..." << std::endl;
113
114 // Perform text input
115 std::string line;
116 while (getline(std::cin, line))
117 {
118 if (line.empty())

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