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

Function test_deferred

example/cpp14/operations/composed_7.cpp:194–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messagesFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected