base_from_completion_cond.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // detail/base_from_completion_cond.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
  11. #define ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/completion_condition.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. namespace detail {
  20. template <typename CompletionCondition>
  21. class base_from_completion_cond
  22. {
  23. protected:
  24. explicit base_from_completion_cond(CompletionCondition& completion_condition)
  25. : completion_condition_(
  26. static_cast<CompletionCondition&&>(completion_condition))
  27. {
  28. }
  29. std::size_t check_for_completion(
  30. const asio::error_code& ec,
  31. std::size_t total_transferred)
  32. {
  33. return detail::adapt_completion_condition_result(
  34. completion_condition_(ec, total_transferred));
  35. }
  36. private:
  37. CompletionCondition completion_condition_;
  38. };
  39. template <>
  40. class base_from_completion_cond<transfer_all_t>
  41. {
  42. protected:
  43. explicit base_from_completion_cond(transfer_all_t)
  44. {
  45. }
  46. static std::size_t check_for_completion(
  47. const asio::error_code& ec,
  48. std::size_t total_transferred)
  49. {
  50. return transfer_all_t()(ec, total_transferred);
  51. }
  52. };
  53. } // namespace detail
  54. } // namespace asio
  55. #include "asio/detail/pop_options.hpp"
  56. #endif // ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP