win_event.ipp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // detail/win_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_WIN_EVENT_IPP
  11. #define BOOST_ASIO_DETAIL_IMPL_WIN_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)
  17. #include <boost/asio/detail/throw_error.hpp>
  18. #include <boost/asio/detail/win_event.hpp>
  19. #include <boost/asio/error.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. namespace detail {
  24. win_event::win_event()
  25. : state_(0)
  26. {
  27. #if defined(BOOST_ASIO_WINDOWS_APP)
  28. events_[0] = ::CreateEventExW(0, 0,
  29. CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
  30. #else // defined(BOOST_ASIO_WINDOWS_APP)
  31. events_[0] = ::CreateEventW(0, true, false, 0);
  32. #endif // defined(BOOST_ASIO_WINDOWS_APP)
  33. if (!events_[0])
  34. {
  35. DWORD last_error = ::GetLastError();
  36. boost::system::error_code ec(last_error,
  37. boost::asio::error::get_system_category());
  38. boost::asio::detail::throw_error(ec, "event");
  39. }
  40. #if defined(BOOST_ASIO_WINDOWS_APP)
  41. events_[1] = ::CreateEventExW(0, 0, 0, EVENT_ALL_ACCESS);
  42. #else // defined(BOOST_ASIO_WINDOWS_APP)
  43. events_[1] = ::CreateEventW(0, false, false, 0);
  44. #endif // defined(BOOST_ASIO_WINDOWS_APP)
  45. if (!events_[1])
  46. {
  47. DWORD last_error = ::GetLastError();
  48. ::CloseHandle(events_[0]);
  49. boost::system::error_code ec(last_error,
  50. boost::asio::error::get_system_category());
  51. boost::asio::detail::throw_error(ec, "event");
  52. }
  53. }
  54. win_event::~win_event()
  55. {
  56. ::CloseHandle(events_[0]);
  57. ::CloseHandle(events_[1]);
  58. }
  59. } // namespace detail
  60. } // namespace asio
  61. } // namespace boost
  62. #include <boost/asio/detail/pop_options.hpp>
  63. #endif // defined(BOOST_ASIO_WINDOWS)
  64. #endif // BOOST_ASIO_DETAIL_IMPL_WIN_EVENT_IPP