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