| 185 | //------------------------------------------------------------------------------ |
| 186 | |
| 187 | void test_deferred() |
| 188 | { |
| 189 | boost::asio::io_context io_context; |
| 190 | |
| 191 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 192 | tcp::socket socket = acceptor.accept(); |
| 193 | |
| 194 | // Test our asynchronous operation using the deferred completion token. This |
| 195 | // token causes the operation's initiating function to package up the |
| 196 | // operation with its arguments to return a function object, which may then be |
| 197 | // used to launch the asynchronous operation. |
| 198 | auto op = async_write_messages(socket, |
| 199 | "Testing deferred\r\n", 5, boost::asio::deferred); |
| 200 | |
| 201 | // Launch the operation using a lambda as a callback. |
| 202 | std::move(op)( |
| 203 | [](const boost::system::error_code& error) |
| 204 | { |
| 205 | if (!error) |
| 206 | { |
| 207 | std::cout << "Messages sent\n"; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | std::cout << "Error: " << error.message() << "\n"; |
| 212 | } |
| 213 | }); |
| 214 | |
| 215 | io_context.run(); |
| 216 | } |
| 217 | |
| 218 | //------------------------------------------------------------------------------ |
| 219 |
no test coverage detected