MCPcopy Create free account
hub / github.com/boostorg/asio / main

Function main

example/cpp11/invocation/prioritised_handlers.cpp:169–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167};
168
169int 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}

Callers

nothing calls this directly

Calls 9

execute_allMethod · 0.80
postFunction · 0.50
wrapMethod · 0.45
async_acceptMethod · 0.45
connectMethod · 0.45
local_endpointMethod · 0.45
expires_atMethod · 0.45
async_waitMethod · 0.45

Tested by

no test coverage detected