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

Function test_future

example/cpp20/operations/composed_2.cpp:191–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189//------------------------------------------------------------------------------
190
191void test_future()
192{
193 boost::asio::io_context io_context;
194
195 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
196 tcp::socket socket = acceptor.accept();
197
198 // Test our asynchronous operation using the use_future completion token.
199 // This token causes the operation's initiating function to return a future,
200 // which may be used to synchronously wait for the result of the operation.
201 std::future<std::size_t> f = async_write_message(
202 socket, "Testing future\r\n", false, boost::asio::use_future);
203
204 io_context.run();
205
206 try
207 {
208 // Get the result of the operation.
209 std::size_t n = f.get();
210 std::cout << n << " bytes transferred\n";
211 }
212 catch (const std::exception& e)
213 {
214 std::cout << "Error: " << e.what() << "\n";
215 }
216}
217
218//------------------------------------------------------------------------------
219

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