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

Function test_deferred

example/cpp11/operations/composed_2.cpp:162–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected