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

Function compose_total_cancellation_test

test/compose.cpp:440–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438}
439
440void compose_total_cancellation_test()
441{
442 namespace bindns = std;
443 using bindns::placeholders::_1;
444
445 boost::asio::io_context ioc;
446 boost::asio::system_timer timer(ioc);
447 boost::asio::cancellation_signal signal;
448 int count = 0;
449 bool result = false;
450
451 async_cancellable(boost::asio::enable_total_cancellation(), timer,
452 bindns::bind(&compose_partial_cancellation_handler,
453 &count, &result, _1));
454
455 ioc.run();
456
457 // No cancellation, operation completes successfully.
458
459 BOOST_ASIO_CHECK(ioc.stopped());
460 BOOST_ASIO_CHECK(count == 1);
461 BOOST_ASIO_CHECK(result == true);
462
463 ioc.restart();
464 count = 0;
465 result = 0;
466
467 async_cancellable(boost::asio::enable_total_cancellation(), timer,
468 boost::asio::bind_cancellation_slot(signal.slot(),
469 bindns::bind(&compose_partial_cancellation_handler,
470 &count, &result, _1)));
471
472 // Total cancellation works. Operation completes with failure.
473 signal.emit(boost::asio::cancellation_type::total);
474
475 ioc.run();
476
477 BOOST_ASIO_CHECK(ioc.stopped());
478 BOOST_ASIO_CHECK(count == 1);
479 BOOST_ASIO_CHECK(result == false);
480
481 ioc.restart();
482 count = 0;
483 result = 0;
484
485 async_cancellable(boost::asio::enable_total_cancellation(), timer,
486 boost::asio::bind_cancellation_slot(signal.slot(),
487 bindns::bind(&compose_partial_cancellation_handler,
488 &count, &result, _1)));
489
490 // Partial cancellation works. Operation completes with failure.
491 signal.emit(boost::asio::cancellation_type::partial);
492
493 ioc.run();
494
495 BOOST_ASIO_CHECK(ioc.stopped());
496 BOOST_ASIO_CHECK(count == 1);
497 BOOST_ASIO_CHECK(result == false);

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