| 211 | //------------------------------------------------------------------------------ |
| 212 | |
| 213 | void test_deferred() |
| 214 | { |
| 215 | boost::asio::io_context io_context; |
| 216 | |
| 217 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 218 | tcp::socket socket = acceptor.accept(); |
| 219 | |
| 220 | // Test our asynchronous operation using the deferred completion token. This |
| 221 | // token causes the operation's initiating function to package up the |
| 222 | // operation with its arguments to return a function object, which may then be |
| 223 | // used to launch the asynchronous operation. |
| 224 | auto op = async_write_message(socket, |
| 225 | std::string("abcdef"), boost::asio::deferred); |
| 226 | |
| 227 | // Launch the operation using a lambda as a callback. |
| 228 | std::move(op)( |
| 229 | [](const boost::system::error_code& error) |
| 230 | { |
| 231 | if (!error) |
| 232 | { |
| 233 | std::cout << "Message sent\n"; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | std::cout << "Error: " << error.message() << "\n"; |
| 238 | } |
| 239 | }); |
| 240 | |
| 241 | io_context.run(); |
| 242 | } |
| 243 | |
| 244 | //------------------------------------------------------------------------------ |
| 245 |
no test coverage detected