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

Function test_deferred

example/cpp14/operations/composed_2.cpp:152–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150//------------------------------------------------------------------------------
151
152void test_deferred()
153{
154 boost::asio::io_context io_context;
155
156 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
157 tcp::socket socket = acceptor.accept();
158
159 // Test our asynchronous operation using the deferred completion token. This
160 // token causes the operation's initiating function to package up the
161 // operation with its arguments to return a function object, which may then be
162 // used to launch the asynchronous operation.
163 auto op = async_write_message(socket,
164 "Testing deferred\r\n", false, boost::asio::deferred);
165
166 // Launch the operation using a lambda as a callback.
167 std::move(op)(
168 [](const boost::system::error_code& error, std::size_t n)
169 {
170 if (!error)
171 {
172 std::cout << n << " bytes transferred\n";
173 }
174 else
175 {
176 std::cout << "Error: " << error.message() << "\n";
177 }
178 });
179
180 io_context.run();
181}
182
183//------------------------------------------------------------------------------
184

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected