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

Function test_future

example/cpp14/operations/composed_1.cpp:121–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119//------------------------------------------------------------------------------
120
121void test_future()
122{
123 boost::asio::io_context io_context;
124
125 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
126 tcp::socket socket = acceptor.accept();
127
128 // Test our asynchronous operation using the use_future completion token.
129 // This token causes the operation's initiating function to return a future,
130 // which may be used to synchronously wait for the result of the operation.
131 std::future<std::size_t> f = async_write_message(
132 socket, "Testing future\r\n", boost::asio::use_future);
133
134 io_context.run();
135
136 try
137 {
138 // Get the result of the operation.
139 std::size_t n = f.get();
140 std::cout << n << " bytes transferred\n";
141 }
142 catch (const std::exception& e)
143 {
144 std::cout << "Error: " << e.what() << "\n";
145 }
146}
147
148//------------------------------------------------------------------------------
149

Callers 1

mainFunction · 0.70

Calls 4

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected