| 121 | //------------------------------------------------------------------------------ |
| 122 | |
| 123 | void test_future() |
| 124 | { |
| 125 | boost::asio::io_context io_context; |
| 126 | |
| 127 | tcp::acceptor acceptor(io_context, {tcp::v4(), 55555}); |
| 128 | tcp::socket socket = acceptor.accept(); |
| 129 | |
| 130 | // Test our asynchronous operation using the use_future completion token. |
| 131 | // This token causes the operation's initiating function to return a future, |
| 132 | // which may be used to synchronously wait for the result of the operation. |
| 133 | std::future<std::size_t> f = async_write_message( |
| 134 | socket, "Testing future\r\n", boost::asio::use_future); |
| 135 | |
| 136 | io_context.run(); |
| 137 | |
| 138 | try |
| 139 | { |
| 140 | // Get the result of the operation. |
| 141 | std::size_t n = f.get(); |
| 142 | std::cout << n << " bytes transferred\n"; |
| 143 | } |
| 144 | catch (const std::exception& e) |
| 145 | { |
| 146 | std::cout << "Error: " << e.what() << "\n"; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | //------------------------------------------------------------------------------ |
| 151 |
no test coverage detected