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

Function test_deferred

example/cpp20/operations/composed_2.cpp:158–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected