wait_traits.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // wait_traits.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_WAIT_TRAITS_HPP
  11. #define BOOST_ASIO_WAIT_TRAITS_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/push_options.hpp>
  16. namespace boost {
  17. namespace asio {
  18. /// Wait traits suitable for use with the basic_waitable_timer class template.
  19. template <typename Clock>
  20. struct wait_traits
  21. {
  22. /// Convert a clock duration into a duration used for waiting.
  23. /**
  24. * @returns @c d.
  25. */
  26. static typename Clock::duration to_wait_duration(
  27. const typename Clock::duration& d)
  28. {
  29. return d;
  30. }
  31. /// Convert a clock duration into a duration used for waiting.
  32. /**
  33. * @returns @c d.
  34. */
  35. static typename Clock::duration to_wait_duration(
  36. const typename Clock::time_point& t)
  37. {
  38. typename Clock::time_point now = Clock::now();
  39. if (now + (Clock::duration::max)() < t)
  40. return (Clock::duration::max)();
  41. if (now + (Clock::duration::min)() > t)
  42. return (Clock::duration::min)();
  43. return t - now;
  44. }
  45. };
  46. } // namespace asio
  47. } // namespace boost
  48. #include <boost/asio/detail/pop_options.hpp>
  49. #endif // BOOST_ASIO_WAIT_TRAITS_HPP