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

Function main

example/cpp20/coroutines/chat_server.cpp:191–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189//----------------------------------------------------------------------
190
191int main(int argc, char* argv[])
192{
193 try
194 {
195 if (argc < 2)
196 {
197 std::cerr << "Usage: chat_server <port> [<port> ...]\n";
198 return 1;
199 }
200
201 boost::asio::io_context io_context(1);
202
203 for (int i = 1; i < argc; ++i)
204 {
205 unsigned short port = std::atoi(argv[i]);
206 co_spawn(io_context,
207 listener(tcp::acceptor(io_context, {tcp::v4(), port})),
208 detached);
209 }
210
211 boost::asio::signal_set signals(io_context, SIGINT, SIGTERM);
212 signals.async_wait([&](auto, auto){ io_context.stop(); });
213
214 io_context.run();
215 }
216 catch (std::exception& e)
217 {
218 std::cerr << "Exception: " << e.what() << "\n";
219 }
220
221 return 0;
222}

Callers

nothing calls this directly

Calls 5

listenerFunction · 0.70
co_spawnFunction · 0.50
async_waitMethod · 0.45
stopMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected