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

Function compose_default_cancellation_test

test/composed.cpp:286–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284}
285
286void compose_default_cancellation_test()
287{
288 namespace bindns = std;
289 using bindns::placeholders::_1;
290
291 boost::asio::io_context ioc;
292 boost::asio::system_timer timer(ioc);
293 boost::asio::cancellation_signal signal;
294 int count = 0;
295 bool result = false;
296
297 async_cancellable(default_filter(), timer,
298 bindns::bind(&compose_partial_cancellation_handler,
299 &count, &result, _1));
300
301 ioc.run();
302
303 // No cancellation, operation completes successfully.
304
305 BOOST_ASIO_CHECK(ioc.stopped());
306 BOOST_ASIO_CHECK(count == 1);
307 BOOST_ASIO_CHECK(result == true);
308
309 ioc.restart();
310 count = 0;
311 result = 0;
312
313 async_cancellable(default_filter(), timer,
314 boost::asio::bind_cancellation_slot(signal.slot(),
315 bindns::bind(&compose_partial_cancellation_handler,
316 &count, &result, _1)));
317
318 // Total cancellation unsupported. Operation completes successfully.
319 signal.emit(boost::asio::cancellation_type::total);
320
321 ioc.run();
322
323 BOOST_ASIO_CHECK(ioc.stopped());
324 BOOST_ASIO_CHECK(count == 1);
325 BOOST_ASIO_CHECK(result == true);
326
327 ioc.restart();
328 count = 0;
329 result = 0;
330
331 async_cancellable(default_filter(), timer,
332 boost::asio::bind_cancellation_slot(signal.slot(),
333 bindns::bind(&compose_partial_cancellation_handler,
334 &count, &result, _1)));
335
336 // Partial cancellation unsupported. Operation completes successfully.
337 signal.emit(boost::asio::cancellation_type::partial);
338
339 ioc.run();
340
341 BOOST_ASIO_CHECK(ioc.stopped());
342 BOOST_ASIO_CHECK(count == 1);
343 BOOST_ASIO_CHECK(result == true);

Callers

nothing calls this directly

Calls 7

restartMethod · 0.80
emitMethod · 0.80
async_cancellableFunction · 0.70
bindFunction · 0.50
runMethod · 0.45
stoppedMethod · 0.45
slotMethod · 0.45

Tested by

no test coverage detected