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

Function test_deferred

example/cpp14/operations/composed_1.cpp:88–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86//------------------------------------------------------------------------------
87
88void test_deferred()
89{
90 boost::asio::io_context io_context;
91
92 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
93 tcp::socket socket = acceptor.accept();
94
95 // Test our asynchronous operation using the deferred completion token. This
96 // token causes the operation's initiating function to package up the
97 // operation with its arguments to return a function object, which may then be
98 // used to launch the asynchronous operation.
99 auto op = async_write_message(socket,
100 "Testing deferred\r\n", boost::asio::deferred);
101
102 // Launch the operation using a lambda as a callback.
103 std::move(op)(
104 [](const boost::system::error_code& error, std::size_t n)
105 {
106 if (!error)
107 {
108 std::cout << n << " bytes transferred\n";
109 }
110 else
111 {
112 std::cout << "Error: " << error.message() << "\n";
113 }
114 });
115
116 io_context.run();
117}
118
119//------------------------------------------------------------------------------
120

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected