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