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