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

Function test_deferred

example/cpp20/operations/composed_3.cpp:164–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected