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

Function any_completion_handler_associator_test

test/any_completion_handler.cpp:170–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168};
169
170void any_completion_handler_associator_test()
171{
172 typedef boost::asio::any_completion_handler<void()> handler_type;
173
174 int count = 0;
175 int alloc_count = 0;
176 int cancel_count = 0;
177 boost::asio::thread_pool pool(1);
178 boost::asio::cancellation_signal sig;
179
180 boost::asio::any_completion_handler<void()> h1(
181 boost::asio::bind_allocator(handler_allocator<char>(&alloc_count),
182 boost::asio::bind_cancellation_slot(sig.slot(),
183 boost::asio::bind_executor(pool.get_executor(),
184 boost::asio::bind_immediate_executor(boost::asio::inline_executor(),
185 bindns::bind(&increment, &count))))));
186
187 BOOST_ASIO_CHECK(alloc_count == 1);
188
189 BOOST_ASIO_REBIND_ALLOC(boost::asio::associated_allocator<handler_type>::type,
190 char) alloc1(boost::asio::get_associated_allocator(h1));
191 alloc1.deallocate(alloc1.allocate(1), 1);
192
193 BOOST_ASIO_CHECK(alloc_count == 2);
194
195 boost::asio::associated_cancellation_slot<handler_type>::type slot1
196 = boost::asio::get_associated_cancellation_slot(h1);
197
198 BOOST_ASIO_CHECK(slot1.is_connected());
199
200 slot1.emplace<cancel_handler>(&cancel_count);
201
202 BOOST_ASIO_CHECK(cancel_count == 0);
203
204 sig.emit(boost::asio::cancellation_type::terminal);
205
206 BOOST_ASIO_CHECK(cancel_count == 1);
207
208 boost::asio::associated_executor<handler_type>::type ex1
209 = boost::asio::get_associated_executor(h1);
210
211 BOOST_ASIO_CHECK(ex1 == pool.get_executor());
212
213 boost::asio::associated_immediate_executor<
214 handler_type, boost::asio::thread_pool::executor_type>::type ex2
215 = boost::asio::get_associated_immediate_executor(h1, pool.get_executor());
216
217 BOOST_ASIO_CHECK(ex2 == boost::asio::inline_executor());
218}
219
220void increment_with_error(boost::system::error_code ec,
221 boost::system::error_code* out_ec, int* count)

Callers

nothing calls this directly

Calls 11

get_associated_allocatorFunction · 0.85
get_associated_executorFunction · 0.85
is_connectedMethod · 0.80
emitMethod · 0.80
bindFunction · 0.50
slotMethod · 0.45
get_executorMethod · 0.45
deallocateMethod · 0.45
allocateMethod · 0.45

Tested by

no test coverage detected