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

Function main

performance/ssl_echo_server.cpp:52–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50};
51
52int main(int argc, char** argv)
53{
54 auto parser = optparse::OptionParser().version("1.0.0.0");
55
56 parser.add_option("-p", "--port").dest("port").action("store").type("int").set_default(2222).help("Server port. Default: %default");
57 parser.add_option("-t", "--threads").dest("threads").action("store").type("int").set_default(CPU::PhysicalCores()).help("Count of working threads. Default: %default");
58
59 optparse::Values options = parser.parse_args(argc, argv);
60
61 // Print help
62 if (options.get("help"))
63 {
64 parser.print_help();
65 return 0;
66 }
67
68 // Server port
69 int port = options.get("port");
70 int threads = options.get("threads");
71
72 std::cout << "Server port: " << port << std::endl;
73 std::cout << "Working threads: " << threads << std::endl;
74
75 std::cout << std::endl;
76
77 // Create a new Asio service
78 auto service = std::make_shared<Service>(threads);
79
80 // Start the Asio service
81 std::cout << "Asio service starting...";
82 service->Start();
83 std::cout << "Done!" << std::endl;
84
85 // Create and prepare a new SSL server context
86 auto context = std::make_shared<SSLContext>(asio::ssl::context::tlsv13);
87 context->set_password_callback([](size_t max_length, asio::ssl::context::password_purpose purpose) -> std::string { return "qwerty"; });
88 context->use_certificate_chain_file("../tools/certificates/server.pem");
89 context->use_private_key_file("../tools/certificates/server.pem", asio::ssl::context::pem);
90 context->use_tmp_dh_file("../tools/certificates/dh4096.pem");
91
92 // Create a new echo server
93 auto server = std::make_shared<EchoServer>(service, context, port);
94 // server->SetupNoDelay(true);
95 server->SetupReuseAddress(true);
96 server->SetupReusePort(true);
97
98 // Start the server
99 std::cout << "Server starting...";
100 server->Start();
101 std::cout << "Done!" << std::endl;
102
103 std::cout << "Press Enter to stop the server or '!' to restart the server..." << std::endl;
104
105 // Perform text input
106 std::string line;
107 while (getline(std::cin, line))
108 {
109 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