| 156 | //------------------------------------------------------------------------------ |
| 157 | |
| 158 | void test_deferred() |
| 159 | { |
| 160 | boost::asio::io_context io_context; |
| 161 | |
| 162 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 163 | tcp::socket socket = acceptor.accept(); |
| 164 | |
| 165 | // Test our asynchronous operation using the deferred completion token. This |
| 166 | // token causes the operation's initiating function to package up the |
| 167 | // operation with its arguments to return a function object, which may then be |
| 168 | // used to launch the asynchronous operation. |
| 169 | boost::asio::async_operation auto op = async_write_message( |
| 170 | socket, "Testing deferred\r\n", false, boost::asio::deferred); |
| 171 | |
| 172 | // Launch the operation using a lambda as a callback. |
| 173 | std::move(op)( |
| 174 | [](const boost::system::error_code& error, std::size_t n) |
| 175 | { |
| 176 | if (!error) |
| 177 | { |
| 178 | std::cout << n << " bytes transferred\n"; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | std::cout << "Error: " << error.message() << "\n"; |
| 183 | } |
| 184 | }); |
| 185 | |
| 186 | io_context.run(); |
| 187 | } |
| 188 | |
| 189 | //------------------------------------------------------------------------------ |
| 190 |
no test coverage detected