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

Function test_deferred

example/cpp11/operations/composed_1.cpp:92–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected