null_event.ipp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // detail/impl/null_event.ipp
  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_IMPL_NULL_EVENT_IPP
  11. #define BOOST_ASIO_DETAIL_IMPL_NULL_EVENT_IPP
  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. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  17. # include <thread>
  18. #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  19. # include <boost/asio/detail/socket_types.hpp>
  20. #else
  21. # include <unistd.h>
  22. # if defined(__hpux)
  23. # include <sys/time.h>
  24. # endif
  25. # if !defined(__hpux) || defined(__SELECT)
  26. # include <sys/select.h>
  27. # endif
  28. #endif
  29. #include <boost/asio/detail/push_options.hpp>
  30. namespace boost {
  31. namespace asio {
  32. namespace detail {
  33. void null_event::do_wait()
  34. {
  35. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  36. std::this_thread::sleep_until((std::chrono::steady_clock::time_point::max)());
  37. #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  38. ::Sleep(INFINITE);
  39. #else
  40. ::pause();
  41. #endif
  42. }
  43. void null_event::do_wait_for_usec(long usec)
  44. {
  45. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  46. std::this_thread::sleep_for(std::chrono::microseconds(usec));
  47. #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  48. ::Sleep(usec / 1000);
  49. #elif defined(__hpux) && defined(__SELECT)
  50. timespec ts;
  51. ts.tv_sec = usec / 1000000;
  52. ts.tv_nsec = (usec % 1000000) * 1000;
  53. ::pselect(0, 0, 0, 0, &ts, 0);
  54. #else
  55. timeval tv;
  56. tv.tv_sec = usec / 1000000;
  57. tv.tv_usec = usec % 1000000;
  58. ::select(0, 0, 0, 0, &tv);
  59. #endif
  60. }
  61. } // namespace detail
  62. } // namespace asio
  63. } // namespace boost
  64. #include <boost/asio/detail/pop_options.hpp>
  65. #endif // BOOST_ASIO_DETAIL_IMPL_NULL_EVENT_IPP