| 167 | }; |
| 168 | |
| 169 | int main() |
| 170 | { |
| 171 | boost::asio::io_context io_context; |
| 172 | |
| 173 | handler_priority_queue pri_queue; |
| 174 | |
| 175 | // Post a completion handler to be run immediately. |
| 176 | boost::asio::post(io_context, pri_queue.wrap(0, low_priority_handler())); |
| 177 | |
| 178 | // Start an asynchronous accept that will complete immediately. |
| 179 | tcp::endpoint endpoint(boost::asio::ip::address_v4::loopback(), 0); |
| 180 | tcp::acceptor acceptor(io_context, endpoint); |
| 181 | tcp::socket server_socket(io_context); |
| 182 | acceptor.async_accept(pri_queue.wrap(100, high_priority_handler)); |
| 183 | tcp::socket client_socket(io_context); |
| 184 | client_socket.connect(acceptor.local_endpoint()); |
| 185 | |
| 186 | // Set a deadline timer to expire immediately. |
| 187 | boost::asio::steady_timer timer(io_context); |
| 188 | timer.expires_at(boost::asio::steady_timer::clock_type::time_point::min()); |
| 189 | timer.async_wait(pri_queue.wrap(42, middle_priority_handler)); |
| 190 | |
| 191 | while (io_context.run_one()) |
| 192 | { |
| 193 | // The custom invocation hook adds the handlers to the priority queue |
| 194 | // rather than executing them from within the poll_one() call. |
| 195 | while (io_context.poll_one()) |
| 196 | ; |
| 197 | |
| 198 | pri_queue.execute_all(); |
| 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | } |
nothing calls this directly
no test coverage detected