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

Function main

example/cpp11/services/daytime_client.cpp:65–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65int main(int argc, char* argv[])
66{
67 try
68 {
69 if (argc != 2)
70 {
71 std::cerr << "Usage: daytime_client <host>" << std::endl;
72 return 1;
73 }
74
75 boost::asio::io_context io_context;
76
77 // Set the name of the file that all logger instances will use.
78 services::logger logger(io_context, "");
79 logger.use_file("log.txt");
80
81 // Resolve the address corresponding to the given host.
82 tcp::resolver resolver(io_context);
83 tcp::resolver::results_type endpoints =
84 resolver.resolve(argv[1], "daytime");
85
86 // Start an asynchronous connect.
87 tcp::socket socket(io_context);
88 boost::asio::async_connect(socket, endpoints,
89 std::bind(connect_handler,
90 boost::asio::placeholders::error, &socket));
91
92 // Run the io_context until all operations have finished.
93 io_context.run();
94 }
95 catch (std::exception& e)
96 {
97 std::cerr << e.what() << std::endl;
98 }
99
100 return 0;
101}

Callers

nothing calls this directly

Calls 5

async_connectFunction · 0.50
bindFunction · 0.50
use_fileMethod · 0.45
resolveMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected