| 284 | } |
| 285 | |
| 286 | void 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); |