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

Function main

example/cpp11/spawn/echo_server.cpp:74–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72};
73
74int main(int argc, char* argv[])
75{
76 try
77 {
78 if (argc != 2)
79 {
80 std::cerr << "Usage: echo_server <port>\n";
81 return 1;
82 }
83
84 boost::asio::io_context io_context;
85
86 boost::asio::spawn(io_context,
87 [&](boost::asio::yield_context yield)
88 {
89 tcp::acceptor acceptor(io_context,
90 tcp::endpoint(tcp::v4(), std::atoi(argv[1])));
91
92 for (;;)
93 {
94 boost::system::error_code ec;
95 tcp::socket socket(io_context);
96 acceptor.async_accept(socket, yield[ec]);
97 if (!ec)
98 {
99 std::make_shared<session>(io_context, std::move(socket))->go();
100 }
101 }
102 },
103 [](std::exception_ptr e)
104 {
105 if (e)
106 std::rethrow_exception(e);
107 });
108
109 io_context.run();
110 }
111 catch (std::exception& e)
112 {
113 std::cerr << "Exception: " << e.what() << "\n";
114 }
115
116 return 0;
117}

Callers

nothing calls this directly

Calls 5

spawnFunction · 0.85
goMethod · 0.80
endpointClass · 0.50
async_acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected