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

Function test_deferred

example/cpp11/operations/composed_7.cpp:201–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199//------------------------------------------------------------------------------
200
201void test_deferred()
202{
203 boost::asio::io_context io_context;
204
205 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
206 tcp::socket socket = acceptor.accept();
207
208 // Test our asynchronous operation using the deferred completion token. This
209 // token causes the operation's initiating function to package up the
210 // operation and its arguments to return a function object, which may then be
211 // used to launch the asynchronous operation.
212 auto op = async_write_messages(socket,
213 "Testing deferred\r\n", 5, boost::asio::deferred);
214
215 // Launch the operation using a lambda as a callback.
216 std::move(op)(
217 [](const boost::system::error_code& error)
218 {
219 if (!error)
220 {
221 std::cout << "Messages sent\n";
222 }
223 else
224 {
225 std::cout << "Error: " << error.message() << "\n";
226 }
227 });
228
229 io_context.run();
230}
231
232//------------------------------------------------------------------------------
233

Callers 1

mainFunction · 0.70

Calls 3

async_write_messagesFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected