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