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