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

Function test_deferred

example/cpp14/operations/composed_5.cpp:213–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211//------------------------------------------------------------------------------
212
213void test_deferred()
214{
215 boost::asio::io_context io_context;
216
217 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
218 tcp::socket socket = acceptor.accept();
219
220 // Test our asynchronous operation using the deferred completion token. This
221 // token causes the operation's initiating function to package up the
222 // operation with its arguments to return a function object, which may then be
223 // used to launch the asynchronous operation.
224 auto op = async_write_message(socket,
225 std::string("abcdef"), boost::asio::deferred);
226
227 // Launch the operation using a lambda as a callback.
228 std::move(op)(
229 [](const boost::system::error_code& error)
230 {
231 if (!error)
232 {
233 std::cout << "Message sent\n";
234 }
235 else
236 {
237 std::cout << "Error: " << error.message() << "\n";
238 }
239 });
240
241 io_context.run();
242}
243
244//------------------------------------------------------------------------------
245

Callers 1

mainFunction · 0.70

Calls 4

stringFunction · 0.85
async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected