| 277 | //------------------------------------------------------------------------------ |
| 278 | |
| 279 | void test_deferred() |
| 280 | { |
| 281 | boost::asio::io_context io_context; |
| 282 | |
| 283 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 284 | tcp::socket socket = acceptor.accept(); |
| 285 | |
| 286 | // Test our asynchronous operation using the deferred completion token. This |
| 287 | // token causes the operation's initiating function to package up the |
| 288 | // operation with its arguments to return a function object, which may then be |
| 289 | // used to launch the asynchronous operation. |
| 290 | boost::asio::async_operation auto op = async_write_messages( |
| 291 | socket, "Testing deferred\r\n", 5, boost::asio::deferred); |
| 292 | |
| 293 | // Launch the operation using a lambda as a callback. |
| 294 | std::move(op)( |
| 295 | [](const boost::system::error_code& error) |
| 296 | { |
| 297 | if (!error) |
| 298 | { |
| 299 | std::cout << "Messages sent\n"; |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | std::cout << "Error: " << error.message() << "\n"; |
| 304 | } |
| 305 | }); |
| 306 | |
| 307 | io_context.run(); |
| 308 | } |
| 309 | |
| 310 | //------------------------------------------------------------------------------ |
| 311 |
no test coverage detected