| 281 | //------------------------------------------------------------------------------ |
| 282 | |
| 283 | void test_deferred() |
| 284 | { |
| 285 | boost::asio::io_context io_context; |
| 286 | |
| 287 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 288 | tcp::socket socket = acceptor.accept(); |
| 289 | |
| 290 | // Test our asynchronous operation using the deferred completion token. This |
| 291 | // token causes the operation's initiating function to package up the |
| 292 | // operation and its arguments to return a function object, which may then be |
| 293 | // used to launch the asynchronous operation. |
| 294 | auto op = async_write_messages(socket, |
| 295 | "Testing deferred\r\n", 5, boost::asio::deferred); |
| 296 | |
| 297 | // Launch the operation using a lambda as a callback. |
| 298 | std::move(op)( |
| 299 | [](const boost::system::error_code& error) |
| 300 | { |
| 301 | if (!error) |
| 302 | { |
| 303 | std::cout << "Messages sent\n"; |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | std::cout << "Error: " << error.message() << "\n"; |
| 308 | } |
| 309 | }); |
| 310 | |
| 311 | io_context.run(); |
| 312 | } |
| 313 | |
| 314 | //------------------------------------------------------------------------------ |
| 315 |
no test coverage detected