base_from_completion_cond.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // detail/base_from_completion_cond.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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 BOOST_ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
  11. #define BOOST_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 <boost/asio/detail/config.hpp>
  16. #include <boost/asio/completion_condition.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. template <typename CompletionCondition>
  22. class base_from_completion_cond
  23. {
  24. protected:
  25. explicit base_from_completion_cond(CompletionCondition completion_condition)
  26. : completion_condition_(completion_condition)
  27. {
  28. }
  29. std::size_t check_for_completion(
  30. const boost::system::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 boost::system::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. } // namespace boost
  56. #include <boost/asio/detail/pop_options.hpp>
  57. #endif // BOOST_ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP