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