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

Function test_deferred

example/cpp11/operations/composed_3.cpp:170–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168//------------------------------------------------------------------------------
169
170void test_deferred()
171{
172 boost::asio::io_context io_context;
173
174 tcp::acceptor acceptor(io_context, {tcp::v4(), 55555});
175 tcp::socket socket = acceptor.accept();
176
177 // Test our asynchronous operation using the deferred completion token. This
178 // token causes the operation's initiating function to package up the
179 // operation and its arguments to return a function object, which may then be
180 // used to launch the asynchronous operation.
181 auto op = async_write_message(socket,
182 "Testing deferred\r\n", boost::asio::deferred);
183
184 // Launch the operation using a lambda as a callback.
185 std::move(op)(
186 [](const boost::system::error_code& error)
187 {
188 if (!error)
189 {
190 std::cout << "Message sent\n";
191 }
192 else
193 {
194 std::cout << "Error: " << error.message() << "\n";
195 }
196 });
197
198 io_context.run();
199}
200
201//------------------------------------------------------------------------------
202

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected