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

Function main

example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp:89–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87//------------------------------------------------------------------------------
88
89int main(int argc, char* argv[])
90{
91 try
92 {
93 // Check command line arguments.
94 if (argc != 3)
95 {
96 std::cerr <<
97 "Usage: websocket-server-sync-ssl <address> <port>\n" <<
98 "Example:\n" <<
99 " websocket-server-sync-ssl 0.0.0.0 8080\n";
100 return EXIT_FAILURE;
101 }
102 auto const address = net::ip::make_address(argv[1]);
103 auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
104
105 // The io_context is required for all I/O
106 net::io_context ioc{1};
107
108 // The SSL context is required, and holds certificates
109 ssl::context ctx{ssl::context::tlsv12};
110
111 // This holds the self-signed certificate used by the server
112 load_server_certificate(ctx);
113
114 // The acceptor receives incoming connections
115 tcp::acceptor acceptor{ioc, {address, port}};
116 for(;;)
117 {
118 // This will receive the new connection
119 tcp::socket socket{ioc};
120
121 // Block until we get a connection
122 acceptor.accept(socket);
123
124 // Launch the session, transferring ownership of the socket
125 std::thread(
126 &do_session,
127 std::move(socket),
128 std::ref(ctx)).detach();
129 }
130 }
131 catch (const std::exception& e)
132 {
133 std::cerr << "Error: " << e.what() << std::endl;
134 return EXIT_FAILURE;
135 }
136}

Callers

nothing calls this directly

Calls 6

load_server_certificateFunction · 0.85
threadClass · 0.85
moveClass · 0.85
refFunction · 0.85
whatMethod · 0.80
acceptMethod · 0.45

Tested by

no test coverage detected