| 90 | //------------------------------------------------------------------------------ |
| 91 | |
| 92 | void test_deferred() |
| 93 | { |
| 94 | boost::asio::io_context io_context; |
| 95 | |
| 96 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 97 | tcp::socket socket = acceptor.accept(); |
| 98 | |
| 99 | // Test our asynchronous operation using the deferred completion token. This |
| 100 | // token causes the operation's initiating function to package up the |
| 101 | // operation and its arguments to return a function object, which may then be |
| 102 | // used to launch the asynchronous operation. |
| 103 | auto op = async_write_message(socket, |
| 104 | "Testing deferred\r\n", boost::asio::deferred); |
| 105 | |
| 106 | // Launch the operation using a lambda as a callback. |
| 107 | std::move(op)( |
| 108 | [](const boost::system::error_code& error, std::size_t n) |
| 109 | { |
| 110 | if (!error) |
| 111 | { |
| 112 | std::cout << n << " bytes transferred\n"; |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | std::cout << "Error: " << error.message() << "\n"; |
| 117 | } |
| 118 | }); |
| 119 | |
| 120 | io_context.run(); |
| 121 | } |
| 122 | |
| 123 | //------------------------------------------------------------------------------ |
| 124 |
no test coverage detected