helper.hpp 892 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Copyright (c) 2018-2023 Marcelo Zimbres Silva ([email protected])
  2. *
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE.txt)
  5. */
  6. #ifndef BOOST_REDIS_HELPER_HPP
  7. #define BOOST_REDIS_HELPER_HPP
  8. #include <boost/asio/cancellation_type.hpp>
  9. namespace boost::redis::detail
  10. {
  11. template <class T>
  12. auto is_cancelled(T const& self)
  13. {
  14. return self.get_cancellation_state().cancelled() != asio::cancellation_type_t::none;
  15. }
  16. #define BOOST_REDIS_CHECK_OP0(X)\
  17. if (ec || redis::detail::is_cancelled(self)) {\
  18. X\
  19. self.complete(!!ec ? ec : asio::error::operation_aborted);\
  20. return;\
  21. }
  22. #define BOOST_REDIS_CHECK_OP1(X)\
  23. if (ec || redis::detail::is_cancelled(self)) {\
  24. X\
  25. self.complete(!!ec ? ec : asio::error::operation_aborted, {});\
  26. return;\
  27. }
  28. } // boost::redis::detail
  29. #endif // BOOST_REDIS_HELPER_HPP