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

Function test_deferred

example/cpp20/operations/composed_4.cpp:180–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 3

async_write_messageFunction · 0.70
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected