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