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

Function compose_total_cancellation_test

test/composed.cpp:442–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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