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

Function test_deferred

example/cpp11/operations/composed_6.cpp:283–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messagesFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected