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

Function test_deferred

example/cpp20/operations/composed_6.cpp:279–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277//------------------------------------------------------------------------------
278
279void test_deferred()
280{
281 boost::asio::io_context io_context;
282
283 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
284 tcp::socket socket = acceptor.accept();
285
286 // Test our asynchronous operation using the deferred completion token. This
287 // token causes the operation's initiating function to package up the
288 // operation with its arguments to return a function object, which may then be
289 // used to launch the asynchronous operation.
290 boost::asio::async_operation auto op = async_write_messages(
291 socket, "Testing deferred\r\n", 5, boost::asio::deferred);
292
293 // Launch the operation using a lambda as a callback.
294 std::move(op)(
295 [](const boost::system::error_code& error)
296 {
297 if (!error)
298 {
299 std::cout << "Messages sent\n";
300 }
301 else
302 {
303 std::cout << "Error: " << error.message() << "\n";
304 }
305 });
306
307 io_context.run();
308}
309
310//------------------------------------------------------------------------------
311

Callers 1

mainFunction · 0.70

Calls 3

async_write_messagesFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected