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

Function compose_partial_cancellation_test

test/composed.cpp:364–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364void compose_partial_cancellation_test()
365{
366 namespace bindns = std;
367 using bindns::placeholders::_1;
368
369 boost::asio::io_context ioc;
370 boost::asio::system_timer timer(ioc);
371 boost::asio::cancellation_signal signal;
372 int count = 0;
373 bool result = false;
374
375 async_cancellable(boost::asio::enable_partial_cancellation(), timer,
376 bindns::bind(&compose_partial_cancellation_handler,
377 &count, &result, _1));
378
379 ioc.run();
380
381 // No cancellation, operation completes successfully.
382
383 BOOST_ASIO_CHECK(ioc.stopped());
384 BOOST_ASIO_CHECK(count == 1);
385 BOOST_ASIO_CHECK(result == true);
386
387 ioc.restart();
388 count = 0;
389 result = 0;
390
391 async_cancellable(boost::asio::enable_partial_cancellation(), timer,
392 boost::asio::bind_cancellation_slot(signal.slot(),
393 bindns::bind(&compose_partial_cancellation_handler,
394 &count, &result, _1)));
395
396 // Total cancellation unsupported. Operation completes successfully.
397 signal.emit(boost::asio::cancellation_type::total);
398
399 ioc.run();
400
401 BOOST_ASIO_CHECK(ioc.stopped());
402 BOOST_ASIO_CHECK(count == 1);
403 BOOST_ASIO_CHECK(result == true);
404
405 ioc.restart();
406 count = 0;
407 result = 0;
408
409 async_cancellable(boost::asio::enable_partial_cancellation(), timer,
410 boost::asio::bind_cancellation_slot(signal.slot(),
411 bindns::bind(&compose_partial_cancellation_handler,
412 &count, &result, _1)));
413
414 // Partial cancellation works. Operation completes with failure.
415 signal.emit(boost::asio::cancellation_type::partial);
416
417 ioc.run();
418
419 BOOST_ASIO_CHECK(ioc.stopped());
420 BOOST_ASIO_CHECK(count == 1);
421 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