base_from_completion_cond.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // detail/base_from_completion_cond.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 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_(completion_condition)
  26. {
  27. }
  28. std::size_t check_for_completion(
  29. const asio::error_code& ec,
  30. std::size_t total_transferred)
  31. {
  32. return detail::adapt_completion_condition_result(
  33. completion_condition_(ec, total_transferred));
  34. }
  35. private:
  36. CompletionCondition completion_condition_;
  37. };
  38. template <>
  39. class base_from_completion_cond<transfer_all_t>
  40. {
  41. protected:
  42. explicit base_from_completion_cond(transfer_all_t)
  43. {
  44. }
  45. static std::size_t check_for_completion(
  46. const asio::error_code& ec,
  47. std::size_t total_transferred)
  48. {
  49. return transfer_all_t()(ec, total_transferred);
  50. }
  51. };
  52. } // namespace detail
  53. } // namespace asio
  54. #include "asio/detail/pop_options.hpp"
  55. #endif // ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP