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

Function test_deferred

example/cpp14/operations/composed_3.cpp:160–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected