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

Function test_deferred

example/cpp11/operations/composed_8.cpp:196–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messagesFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected