| 199 | //------------------------------------------------------------------------------ |
| 200 | |
| 201 | void test_deferred() |
| 202 | { |
| 203 | boost::asio::io_context io_context; |
| 204 | |
| 205 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 206 | tcp::socket socket = acceptor.accept(); |
| 207 | |
| 208 | // Test our asynchronous operation using the deferred completion token. This |
| 209 | // token causes the operation's initiating function to package up the |
| 210 | // operation and its arguments to return a function object, which may then be |
| 211 | // used to launch the asynchronous operation. |
| 212 | auto op = async_write_messages(socket, |
| 213 | "Testing deferred\r\n", 5, boost::asio::deferred); |
| 214 | |
| 215 | // Launch the operation using a lambda as a callback. |
| 216 | std::move(op)( |
| 217 | [](const boost::system::error_code& error) |
| 218 | { |
| 219 | if (!error) |
| 220 | { |
| 221 | std::cout << "Messages sent\n"; |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | std::cout << "Error: " << error.message() << "\n"; |
| 226 | } |
| 227 | }); |
| 228 | |
| 229 | io_context.run(); |
| 230 | } |
| 231 | |
| 232 | //------------------------------------------------------------------------------ |
| 233 |
no test coverage detected