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