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