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